rfc:new_without_parentheses

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
rfc:new_without_parentheses [2024/05/09 15:01] – Add voting vudaltsovrfc:new_without_parentheses [2024/05/28 18:04] (current) – Added Target Version vudaltsov
Line 3: Line 3:
   * Date: 2023-12-29   * Date: 2023-12-29
   * Author: Valentin Udaltsov (udaltsov.valentin@gmail.com)   * Author: Valentin Udaltsov (udaltsov.valentin@gmail.com)
-  * Status: Voting+  * Status: Implemented 
 +  * Target Version: PHP 8.4
   * Discussion: https://externals.io/message/123031   * Discussion: https://externals.io/message/123031
   * First Published at: http://wiki.php.net/rfc/new_without_parentheses   * First Published at: http://wiki.php.net/rfc/new_without_parentheses
-  * Implementation and tests: https://github.com/php/php-src/pull/13029+  * Implementation: https://github.com/php/php-src/pull/13029
  
 ===== Introduction ===== ===== Introduction =====
Line 38: Line 39:
  
 <code php> <code php>
-class MyClass+class MyClass extends ArrayObject
 { {
     const CONSTANT = 'constant';     const CONSTANT = 'constant';
Line 59: Line 60:
     new MyClass()->method(),        // string(6)  "method"     new MyClass()->method(),        // string(6)  "method"
     new MyClass()(),                // string(8)  "__invoke"     new MyClass()(),                // string(8)  "__invoke"
 +    new MyClass(['value'])[0],      // string(5)  "value"
 ); );
  
Line 69: Line 71:
     new $myClass()->method(),        // string(6)  "method"     new $myClass()->method(),        // string(6)  "method"
     new $myClass()(),                // string(8)  "__invoke"     new $myClass()(),                // string(8)  "__invoke"
 +    new $myClass(['value'])[0],      // string(5)  "value"
 ); );
  
Line 78: Line 81:
     new (trim(' MyClass '))()->method(),        // string(6)  "method"     new (trim(' MyClass '))()->method(),        // string(6)  "method"
     new (trim(' MyClass '))()(),                // string(8)  "__invoke"     new (trim(' MyClass '))()(),                // string(8)  "__invoke"
 +    new (trim(' MyClass '))(['value'])[0],      // string(5)  "value"
 ); );
 </code> </code>
Line 89: Line 93:
 new $myClass::$staticProperty; // will continue to work as `new ($myClass::$staticProperty)` new $myClass::$staticProperty; // will continue to work as `new ($myClass::$staticProperty)`
 new $myObject->property; // will continue to work as `new ($myObject->property)` new $myObject->property; // will continue to work as `new ($myObject->property)`
 +new MyArrayConst['class']; // will continue to throw a syntax error
 +new $myArray['class']; // will continue to work as `new ($myArray['class'])`
 </code> </code>
  
Line 108: Line 114:
     // string(8) "__invoke"     // string(8) "__invoke"
     new class { public function __invoke() { return '__invoke'; } }(),     new class { public function __invoke() { return '__invoke'; } }(),
 +    // string(5) "value"
 +    new class (['value']) extends ArrayObject {}[0],
 ); );
 </code> </code>
Line 187: Line 195:
 Voting started on 2024-05-09 and will end on 2024-05-24 00:00 GMT. Voting started on 2024-05-09 and will end on 2024-05-24 00:00 GMT.
  
-<doodle title="Allow to omit parentheses around the new expression as described?" auth="vudaltsov" voteType="single" closed="false" closeon="2024-05-24T00:00:00Z">+<doodle title="Allow to omit parentheses around the new expression as described?" auth="vudaltsov" voteType="single" closed="true" closeon="2024-05-24T00:00:00Z">
    * Yes    * Yes
    * No    * No
Line 194: Line 202:
 ===== Implementation ===== ===== Implementation =====
  
-https://github.com/php/php-src/pull/13029+Pull request contains the final implementation and plenty of tests asserting the expected behavior and backward compatibility: https://github.com/php/php-src/pull/13029
  
 ===== References ===== ===== References =====
rfc/new_without_parentheses.1715266878.txt.gz · Last modified: 2024/05/09 15:01 by vudaltsov