summaryrefslogtreecommitdiff
path: root/Zend/zend_builtin_functions.c
diff options
context:
space:
mode:
authorAndi Gutmans <andi@php.net>2004-10-26 23:25:05 +0000
committerAndi Gutmans <andi@php.net>2004-10-26 23:25:05 +0000
commit6a16f3eb1ddd704ed92bda9ce75608571cb33bdf (patch)
tree807dcc3a8567607bae66b66956eacb36565b87a5 /Zend/zend_builtin_functions.c
parentbb928e70a7989d71620fc268ab3dc6c9a5db94f4 (diff)
downloadphp-git-6a16f3eb1ddd704ed92bda9ce75608571cb33bdf.tar.gz
- 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
Diffstat (limited to 'Zend/zend_builtin_functions.c')
-rw-r--r--Zend/zend_builtin_functions.c19
1 files changed, 16 insertions, 3 deletions
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);
}