get class name for an object.
Posted: Thu Jan 15, 2004 3:32 pm
Hi
Is there a function to return the name of the class an object is an instantiation of?
eg
is there a function such as
that would return "myObj" ???
Ive written one which works fine which relies on the [php_man]var_export[/php_man] function, which ive included below - but I was looking for something a bit better if poss - I'm not sure this is the best way to do it. surely there must be a built in function for doing this
here's what I have:
========================
Is there a function to return the name of the class an object is an instantiation of?
eg
Code: Select all
$someVar = new myObj();Code: Select all
objectType ($someVar);Ive written one which works fine which relies on the [php_man]var_export[/php_man] function, which ive included below - but I was looking for something a bit better if poss - I'm not sure this is the best way to do it. surely there must be a built in function for doing this
here's what I have:
========================
Code: Select all
function getObjectType($object) {
// returns the class name of an object
if (is_object($object)) {
$objString = var_export($object, TRUE);
$spaceA = strpos($objString, " ", 0);
$spaceB = strpos ($objString, " ", $spaceA+1);
return substr($objString, $spaceA, $spaceB - $spaceA);
};
}