I'm looking for a functionality, in the example below called "theFunctionILookFor", that will make the code work.
$myClassName = "someName";
$parentOrInterfaceName = "someParent";
if (theFunctionILookFor($myClassName)) {
echo "is parent";
}
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
Looks like this is my answer: is_subclass_of
It can accept both parameters as strings
http://php.net/manual/en/function.is-subclass-of.php
Try is_subclass_of()
. It can accept both parameters as strings. http://php.net/manual/en/function.is-subclass-of.php
Using the Reflection API, you can construct a ReflectionClass object using the name of the class as well as an object.
You might use this?
http://www.php.net/manual/en/function.get-parent-class.php
From the page:
get_parent_class
(PHP 4, PHP 5, PHP 7)
get_parent_class — Retrieves the parent class name for object or classDescription
string get_parent_class ([ mixed $object ] )
Retrieves the parent class name for object or 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