Re: [RFC] Anonymous Classes

From: Date: Tue, 24 Feb 2015 18:49:36 +0000
Subject: Re: [RFC] Anonymous Classes
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-83682@lists.php.net to get a copy of this message
On Tue, Feb 24, 2015 at 1:37 PM, S.A.N <ua.san.alex@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.

« previous php.internals (#83682) next »