Is there a built-in static method or property to refer to a PHP class so that it will contextually be represented as a string? For example:
Instead of this:
$obj->tempFn('MyClass') //MyClass being the name of the class
I want to do this:
$obj->tempFn(MyClass) //Directly references the class name, instead of a string representation
No. But you can define a constant in your class, that contains the class name, like:
class foo{
const
NAME = 'foo';
}
And access it like foo::NAME
.
In PHP 5.5, you'll be able to use:
foo::class
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With