Re: [RFC] Allow ::class on objects
| From: | Mike Schinkel | Date: | Thu, 09 Jan 2020 23:05:10 +0000 |
| Subject: | Re: [RFC] Allow ::class on objects | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-108084@lists.php.net to get a copy of this message | ||
Hey Marco,
> On Jan 9, 2020, at 5:04 PM, Marcio Almada <marcio.web2@gmail.com> wrote:
>
> Regarding the inclusion of new keywords with similar behavior of
>
:class:
>
> Would Interfaces\FooInterface::trait or
> Traits\FooTrait::interface
> cause a run time error? If I'm not mistaken ::class
> can't trigger
> error because it can't trigger autoload like
> class_exists() calls
> does.
>
> Currently ::class can be used to resolve any name like
> trim::class. IMMO it would be weird to have
> ::class with the
> current no autoload / error free behavior and then ::trait,
> ::function and ::interface
> triggering autoload and emitting some
> error level.
You are absolutely correct. I am so used to PhpStorm highlighting issues that I sometimes assume
that PHP will throw an error/warning for the same.
So if ::interface and ::trait were added, then (tools like) PhpStorm could have enough information
to flag them if developers misspell them or they are otherwise unknown.
> And also it would be weird to have ::trait,
> ::function and
> ::interface with the same loose behavior as
> ::class
Why weird?
I can only assume Foo::trait vs. Bar::interface vs. Baz::class would not be hard to grok, and that
it would would provide more valuable information to a reader than Foo::class vs. Bar:: class vs.
Baz::class.
> in that case, it seems less surprising to have just ::class
> everywhere instead.
How so? I was very surprised when I first realized that I could do MyInterface::class, but I would
not have been surprised by MyInterface::interface.
> ::function
That said you bring up one I did not but would also like ::function as well as ::method
and even ::var or ::variable and ::const or ::constant.
-Mike