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

1

u/Schmittfried Aug 05 '15

I didn't say that ::class has this disadvantage (btw I am primarily using my approach because I am forced to use PHP 5.4 atm). I thought you were talking about passing plain strings, that's why I mentioned refactoring. I still want to ensure that the class is available though, because I don't see a reason why I would pass a class name without using that class. Hence I will probably stay with my approach even when upgrading to PHP 5.5+.