diff options
author | Andrei Zmievski <andrei@php.net> | 2001-03-26 19:03:06 +0000 |
---|---|---|
committer | Andrei Zmievski <andrei@php.net> | 2001-03-26 19:03:06 +0000 |
commit | 54da9024f5be1d47fc75b48684ceba13ce83efe5 (patch) | |
tree | 1fe559f13e89e2dec7c1dadb02479c29c6aa5904 | |
parent | 58aaeed92d6fce30f194c7108e6bc62d6fac73cb (diff) | |
download | php-git-54da9024f5be1d47fc75b48684ceba13ce83efe5.tar.gz |
Making it possible to pass a class name to get_parent_class() as well
as a class instance.
-rw-r--r-- | Zend/zend_builtin_functions.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index 40d5a37ec2..9de2a2503f 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -460,19 +460,30 @@ ZEND_FUNCTION(get_class) } /* }}} */ -/* {{{ proto string get_parent_class(object object) - Retrieves the parent class name */ +/* {{{ proto string get_parent_class(mixed object) + Retrieves the parent class name for object or class. */ ZEND_FUNCTION(get_parent_class) { zval **arg; + zend_class_entry *ce = NULL; if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &arg)==FAILURE) { ZEND_WRONG_PARAM_COUNT(); } - if (((*arg)->type != IS_OBJECT) || !(*arg)->value.obj.ce->parent) { + + if (Z_TYPE_PP(arg) == IS_OBJECT) + ce = Z_OBJCE_PP(arg); + else if (Z_TYPE_PP(arg) == IS_STRING) { + SEPARATE_ZVAL(arg); + zend_str_tolower(Z_STRVAL_PP(arg), Z_STRLEN_PP(arg)); + zend_hash_find(EG(class_table), Z_STRVAL_PP(arg), Z_STRLEN_PP(arg)+1, (void **)&ce); + } + + if (ce && ce->parent) { + RETURN_STRINGL(ce->parent->name, ce->parent->name_length, 1); + } else { RETURN_FALSE; } - RETURN_STRINGL((*arg)->value.obj.ce->parent->name, (*arg)->value.obj.ce->parent->name_length, 1); } /* }}} */ |