shealtiel shealtiel - 2 months ago 22
PHP Question

PHP: instanceof equivalent for a string-represented classname

It's best to explain by an example.
I look for a function "theFunctionILookFor" that will make the code work.

$myClassName = "someName";
$parentOrInterfaceName = "someParent";
if ( theFunctionILookFor ($myClassName)) echo "is parrent";


edit: I try to avoid instantiating the class just to perform this check. I would like to be able to pass 2 string parameters to the checking function

Answer

Looks like this is my answer: is_subclass_of

It can accept both parameters as strings

http://www.php.net/manual/en/function.is-subclass-of.php

Comments