The special ::class constant allows for fully qualified class name resolution at compile, this is useful for namespaced classes.

I’m quoting the PHP manual. But things can be funny sometimes. Let’s go through some examples.

use A\B as C; $_ = C::class; resolves to A\B , which is perfect 🙂

class C { public function f() { $_ = self::class; } } resolves to C , which is perfect 😀

class C { } class D extends C { public function f() { $_ = parent::class; } } resolves to C , which is perfect 😄

class C { public static function f() { $_ = static::class; } } class D extends C { } D::f(); resolves to D , which is perfect 😍

'foo'::class resolves to 'foo' , which is… huh? 🤨

"foo"::class resolves to 'foo' , which is… expected somehow 😕

$a = 'oo'; "f{$a}"::class generates a parse error 🙃

PHP_VERSION::class resolves to 'PHP_VERSION' , which is… strange: It resolves to the fully qualified name of the constant, not the class 🤐