Re: Object and Array Literals
| From: | Sean Coates | Date: | Mon, 06 Jun 2011 19:54:24 +0000 |
| Subject: | Re: Object and Array Literals | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-53075@lists.php.net to get a copy of this message | ||
>>> $foo = {
>>> 'bar' : function(){
>>> echo 'baz';
>>> }
>>> };
>>>
>>> $foo->bar();
>>
>> I guess it's not yet too late to surpass Perl in the front of obscurity...
>
> Since the stuff to the right of the assignment operator (
: in
> this case) is valid PHP, I don't see why this wouldn't be allowed if we adopt the {}
> syntax. It's not much different from this, which is currently valid:
>
> $foo = (object)array(
> 'bar' => function () {
> echo 'baz';
> }
> };
Matthew pointed out to me (on IRC) that this actually doesn't work in current PHP (you
can't call an object property as a closure without one of the proxy functions like
call_user_function_array()). My mistake.
Note that this shouldn't affect the RFC, and this behaviour should be addressed as a separate
issue if people think it should work (FWIW, I do obviously think this should work, but that's a
separate thread, please).
S