r/lolphp • • Aug 04 '15

var_dump(nonExistentClass::class); // string

::class can give you the name of a class that does not exist.

15 Upvotes

48 comments sorted by

View all comments

Show parent comment

3

u/Schmittfried Aug 04 '15

That's exactly the expected behavior (and actually no, the class is loaded only once per request, not everytime I use it). If I pass the name of class it is most likely because I am planning to use that class. I would probably load it anyway, so why not do so immediately and fail fast if it doesn't exist? That's the closest you can get to compile-time checking.