Hey Fabio,

On Wed, 5 Jul 2023 at 18:14, Fabio Carpi <fabioca...@hotmail.com.br> wrote:

> I'm new here on the list... Hello everyone!
>
> I use ::class sometimes to check some classes, but it works with any
> keyword, even if the class doesn't exist.
> The IDE doesn't show the error, and I only detect the error when the
> specific piece of code is running...
>
> <?php
> echo foo::class;
>

See https://3v4l.org/8lL10

`::class` is effectively replaced with a string at compile time:

Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8lL10
function name:  (null)
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext
return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ECHO
     'foo'
    3     1      > RETURN                                                   1


This is by design, since otherwise each `::class` lookup would result in
autoloading, which would be disastrous for large maps of classes (like in
service containers).


Marco Pivetta

https://mastodon.social/@ocramius

https://ocramius.github.io/

Reply via email to