rfc:new_without_parentheses
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:new_without_parentheses [2024/04/23 07:57] – Added Other syntax ideas section vudaltsov | rfc: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: | + | * Status: |
+ | * Target Version: PHP 8.4 | ||
* Discussion: https:// | * Discussion: https:// | ||
* First Published at: http:// | * First Published at: http:// | ||
- | * Implementation | + | * Implementation: |
===== Introduction ===== | ===== Introduction ===== | ||
Line 35: | Line 36: | ||
===== Proposal ===== | ===== Proposal ===== | ||
- | This RFC allows to omit parentheses around the '' | + | This RFC allows to omit parentheses around the '' |
<code php> | <code php> | ||
- | class MyClass | + | class MyClass |
{ | { | ||
const CONSTANT = ' | const CONSTANT = ' | ||
Line 59: | Line 60: | ||
new MyClass()-> | new MyClass()-> | ||
new MyClass()(), | new MyClass()(), | ||
+ | new MyClass([' | ||
); | ); | ||
Line 69: | Line 71: | ||
new $myClass()-> | new $myClass()-> | ||
new $myClass()(), | new $myClass()(), | ||
+ | new $myClass([' | ||
); | ); | ||
Line 78: | Line 81: | ||
new (trim(' | new (trim(' | ||
new (trim(' | new (trim(' | ||
+ | new (trim(' | ||
); | ); | ||
</ | </ | ||
- | This RFC still does not allow to omit parentheses around the '' | + | This RFC does not change behavior of '' |
- | this leads to an ambiguity: | + | |
<code php> | <code php> | ||
- | // Instantiate and then access the instance or instantiate the result of the expression? | + | new MyClass:: |
- | new MyClass:: | + | new $myClass:: |
- | new MyClass:: | + | new MyClass:: |
- | new $myClass::CONSTANT; | + | new $myClass::$staticProperty; // will continue to work as `new ($myClass:: |
- | new $myClass:: | + | new $myObject-> |
- | new $myClass-> | + | new MyArrayConst[' |
- | new $myClass->method(); | + | new $myArray[' |
</ | </ | ||
Line 111: | Line 114: | ||
// string(8) " | // string(8) " | ||
new class { public function __invoke() { return ' | new class { public function __invoke() { return ' | ||
+ | // string(5) " | ||
+ | new class ([' | ||
); | ); | ||
</ | </ | ||
Line 159: | Line 164: | ||
===== Other syntax ideas ===== | ===== Other syntax ideas ===== | ||
+ | |||
+ | Some of the ideas expressed during the discussion of this RFC are listed below. They are orthogonal to this proposal and | ||
+ | require a separate RFC. | ||
==== Allow to omit the new keyword ==== | ==== Allow to omit the new keyword ==== | ||
- | Some languages like Kotlin allow to instantiate | + | Some languages like Kotlin allow to instantiate |
- | + | Omitting the " | |
- | Omitting the " | + | (in Kotlin [[https:// |
- | class " | + | deprecate declaring functions and classes with the same names. |
- | For '' | + | |
==== MyClass:: | ==== MyClass:: | ||
- | Introducing a dedicated static constructor like '' | + | Introducing a dedicated static constructor like '' |
- | existing static or object methods named '' | + | break for already existing static or object methods named '' |
+ | type different from '' | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
Line 180: | Line 188: | ||
PHP 8.4 | PHP 8.4 | ||
+ | |||
+ | ===== Proposed Voting Choices ===== | ||
+ | |||
+ | This is a simple yes-or-no vote to include this feature. 2/3 majority required to pass. | ||
+ | |||
+ | Voting started on 2024-05-09 and will end on 2024-05-24 00:00 GMT. | ||
+ | |||
+ | <doodle title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
+ | |||
+ | ===== Implementation ===== | ||
+ | |||
+ | Pull request contains the final implementation and plenty of tests asserting the expected behavior and backward compatibility: | ||
+ | |||
+ | ===== References ===== | ||
+ | |||
+ | * [[https:// | ||
+ | |||
+ | Old requests for this feature: | ||
+ | |||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | |||
rfc/new_without_parentheses.1713859076.txt.gz · Last modified: 2024/04/23 07:57 by vudaltsov