From: Andi Gutmans Date: Tue, 26 Oct 2004 23:25:05 +0000 (+0000) Subject: - Patch from Andrey Hristov: X-Git-Tag: RELEASE_0_2~827 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6a16f3eb1ddd704ed92bda9ce75608571cb33bdf;p=php - Patch from Andrey Hristov: I have cooked a small patch which allows is_subclass_of() the accept not only an object as first parameter but a string as well. When string is passed the function checks whether the class specified is subclass of the second parameter class a{} class b{} extends a{} is_subclass_of("a", "a") //false is_subclass_of("b", "a") //true currently only objects are allowed as first parameter --- diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index 78de5a5cda..e36052ac20 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -611,12 +611,21 @@ static void is_a_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool only_subclass) ZEND_WRONG_PARAM_COUNT(); } - if (Z_TYPE_PP(obj) != IS_OBJECT) { + if (only_subclass && Z_TYPE_PP(obj) == IS_STRING) { + zend_class_entry **the_ce; + if (zend_lookup_class(Z_STRVAL_PP(obj), Z_STRLEN_PP(obj), &the_ce TSRMLS_CC) == FAILURE) { + zend_error(E_WARNING, "Unknown class passed as parameter"); + RETURN_FALSE; + } + instance_ce = *the_ce; + } else if (Z_TYPE_PP(obj) != IS_OBJECT) { RETURN_FALSE; + } else { + instance_ce = NULL; } /* TBI!! new object handlers */ - if (!HAS_CLASS_ENTRY(**obj)) { + if (Z_TYPE_PP(obj) == IS_OBJECT && !HAS_CLASS_ENTRY(**obj)) { RETURN_FALSE; } @@ -626,7 +635,11 @@ static void is_a_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool only_subclass) retval = 0; } else { if (only_subclass) { - instance_ce = Z_OBJCE_PP(obj)->parent; + if (!instance_ce) { + instance_ce = Z_OBJCE_PP(obj)->parent; + } else { + instance_ce = instance_ce->parent; + } } else { instance_ce = Z_OBJCE_PP(obj); }