Re: [RFC] Allow ::class on objects
| From: | Nikita Popov | Date: | Thu, 09 Jan 2020 20:45:15 +0000 |
| Subject: | Re: [RFC] Allow ::class on objects | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-108074@lists.php.net to get a copy of this message | ||
On Thu, Jan 9, 2020 at 3:28 PM Ralph Schindler <ralph@ralphschindler.com>
wrote:
>
> > Another small RFC, to allow $object::class syntax:
> >
> > https://wiki.php.net/rfc/class_name_literal_on_object
>
> Hi Nikita,
>
> Glad to see enhancements to ::class. Open questions, given:
>
>
> class Foo {}
>
> $foo = new Foo;
> echo $foo::class; // Foo
>
> $fooClass = Foo::class;
> echo $foo::class; // TypeError b/c string?
>
Yes, at least per the current proposal. Whether to allow this is listed as
an open question.
> $fooAnon = new class extends Foo {};
> echo $fooAnon::class; // TypeError or class@anonymous?
The same as get_class($fooAnon), which will be of the form
"class@anonymous\0SOME_PAYLOAD_HERE".
While the part after class@anonymous is cut of when printing in most
places, anonymous classes still do have a unique class name.
Nikita