I know there is a static class
field on PHP 5.5, but I have to stick to PHP 5.4. Is it possible to get the fully qualified class name from a variable?
Example:
namespace My\Awesome\Namespace
class Foo {
}
And somewhere else in the code:
public function bar() {
$var = new \My\Awesome\Namespace\Foo();
// maybe there's something like this??
$fullClassName = get_qualified_classname($var);
// outputs 'My\Awesome\Namespace\Foo'
echo $fullClassName
}
You should be using
get_class
If you are using namespaces this function will return the name of the class including the namespace, so watch out if your code does any checks for this.
This is a direct copy paste example from
here
I know this is an old question, but for people still finding this, I would suggest this approach:
If using PHP 5.5, you can simply do this:
Hope this helps...
More info on ::class here.