Re: [RFC] Object Initializer
| From: | Mike Schinkel | Date: | Fri, 13 Sep 2019 09:47:07 +0000 |
| Subject: | Re: [RFC] Object Initializer | ||
| References: | 1 2 3 4 5 6 7 8 9 10 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-107072@lists.php.net to get a copy of this message | ||
> On Sep 13, 2019, at 2:39 AM, Michał Brzuchalski <michal.brzuchalski@gmail.com> wrote:
> $obj->foo => 123;
> Simply, that's not the way you initialize object property values.
So by the same logic this should be PHP's way to initialize array elements, right?
$arr['foo'] => 123;
But it is not. Obviously we both know that this is the correct syntax:
$arr['foo'] = 123;
So that is why I think it would be more consistent in PHP for object initializers to use
"=>" instead of "=."
But, I myself will not belabor the point beyond this message. Either others will agree with you or
they will suggest to change to "=>" too.
> { $foo = 123 }; // unexpected "}" cause of missing ";"
> $bar = { $foo = 123 }; // unexpected "{" cause it's not allowed in this context
> Both examples are syntax error.
> You can use {} for separating blocks of code, but now if you wanna assign value.
> Everything considered syntax error can be used for feature shaping.
Hmm.
Ok, I will let Arnold reply to you on this if he feels that your reply did not address his concerns.
-Mike