Skip to content

Commit 8608f11

Browse files
committed
Merge branch 'pull-request/141'
2 parents 79d439a + 2faf48f commit 8608f11

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

spec/10-expressions.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,11 @@ $obj2 = clone $obj1; // creates a new Manager that is a deep copy
764764
<i>object-creation-expression:</i>
765765
new <i>class-type-designator</i> ( <i>argument-expression-list<sub>opt</sub></i> )
766766
new <i>class-type-designator</i>
767+
new class ( <i>argument-expression-list<sub>opt</sub></i> )
768+
<i>class-base-clause<sub>opt</sub></i> <i>class-interface-clause<sub>opt</sub></i>
769+
{ <i>class-members<sub>opt</sub></i> }
770+
new class <i>class-base-clause<sub>opt</sub></i> <i>class-interface-clause<sub>opt</sub></i>
771+
{ <i>class-members<sub>opt</sub></i> }
767772

768773
<i>class-type-designator:</i>
769774
<i>qualified-name</i>
@@ -773,9 +778,12 @@ $obj2 = clone $obj1; // creates a new Manager that is a deep copy
773778
**Defined elsewhere**
774779

775780
* [*argument-expression-list*](#function-call-operator)
776-
* [*qualified-name*](09-lexical-structure.md#names)
781+
* [*class-base-clause*](14-classes.md#class-declarations)
782+
* [*class-interface-clause*](14-classes.md#class-declarations)
783+
* [*class-members*](14-classes.md#class-declarations)
777784
* [*expression*](#general-6)
778-
785+
* [*qualified-name*](09-lexical-structure.md#names)
786+
779787
**Constraints**
780788

781789
*qualified-name* must name a class.
@@ -790,8 +798,7 @@ as many as the number of non-optional parameters defined for the class's [constr
790798

791799
**Semantics**
792800

793-
The `new` operator creates an object that is an instance of
794-
the class specified by *class-type-designator*.
801+
The `new` *class-type-designator* forms create an object of the class type specified by *class-type-designator*. The `new class` forms create an object of an *anonymous class type*, a type that has an unspecified name. In all other respects, however, an anonymous class has the same capabilities as a named class type.
795802

796803
If the *class-type-designator* is an expression resulting in a string value,
797804
that string is used as the class name. If the expression results in an object,
@@ -810,8 +817,10 @@ passing it the optional *argument-expression-list*. If the class has no
810817
constructor, the constructor that class inherits (if any) is used. The class
811818
can also specify no constructor definition, in this case the constructor call is omitted.
812819

813-
The result of an *object-creation-expression* is an object
814-
of the type specified by *class-type-designator*.
820+
The result of a named-type *object-creation-expression* is an object of the type specified by *class-type-designator*. The result of an anonymous class *object-creation-expression* is an object of unspecified type. However, this type will subtype all types
821+
provided by *class-base-clause* and *class-interface-clause* and the *class-members* definition should follow the same inheritance and implementation rules as the regular [class declaration](14-classes.md#class-declarations) does.
822+
823+
Each distinct source code expression of the form `new class` results in the class type that is different from that of all other anonymous class types. However, multiple evaluations of the same source code expression of the form `new class` result in instances of the same class type.
815824

816825
Because a constructor call is a function call, the relevant parts of
817826
[function call operator](#function-call-operator) section also apply.
@@ -831,6 +840,12 @@ $p1 = new Point; // create Point(0, 0)
831840
$p1 = new Point(12); // create Point(12, 0)
832841
$cName = 'Point';
833842
$p1 = new $cName(-1, 1); // create Point(-1, 1)
843+
// -----------------------------------------
844+
$v2 = new class (100) extends C1 implements I1, I2 {
845+
public function __construct($p) {
846+
echo "Inside class " . __CLASS__ . " constructor with parameter $p\n";
847+
}
848+
};
834849
```
835850

836851
###Array Creation Operator

0 commit comments

Comments
 (0)