2015-02-24 20:49 GMT+02:00 Philip Sturgeon <pjsturg...@gmail.com>:
> On Tue, Feb 24, 2015 at 1:37 PM, S.A.N <ua.san.a...@gmail.com> wrote:
>> Would have been more useful, inline sintex like JSON:
>>
>> $object =
>> {
>>     'property': $value,
>>     'method':  function (){...}
>> };
>>
>> $object->property;
>> $object->method();
>
> I know what you're saying here, and object literals like this would be
> rather interesting someday. They are, however, quite different to the
> concept of anonymous classes.
>
> JSON syntax would make it very hard for the usual PHP functionality to
> be used. Properties and methods look the same, visibility scopes
> cannot be used, implementing interfaces becomes impossible, traits
> dont have a home, etc. By the time you have catered to all of that you
> have something very different to JSON, and very different to PHP.
>
> Or, you have the syntax being proposed here, which is identical to
> existing declared class syntax other than there being no name.
>
> Another RFC to replace $foo = (object) [ 'foo' => 'bar' ]; someday
> would be nice, but that is not what this is up to.

Yes, is problem - properties and methods look the same, how to solve
this problem in PHP I do not know.
Perhaps PHP could interpret this code:
$object =
{
    'property' => $value,
    'method' => function (){...}
};

AS

$object = new class
{
  public $property = $value;
  public function method (){...}
}

Use case - inline object without inheritance and traits, only the
properties and methods it brief and easily understood JSON syntax, I
think it would be popular with developers of PHP.

Thank.

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to