diff --git a/Zend/tests/bug48770.phpt b/Zend/tests/bug48770.phpt index 40fa84157b716..4e2794a4ad0f2 100644 --- a/Zend/tests/bug48770.phpt +++ b/Zend/tests/bug48770.phpt @@ -1,7 +1,5 @@ --TEST-- Bug #48770 (call_user_func_array() fails to call parent from inheriting class) ---XFAIL-- -See Bug #48770 --FILE-- run('This should work!'); + +?> +--EXPECTF-- +%unicode|string%(26) "A::func: This should work!" +%unicode|string%(26) "A::func: This should work!" + diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 90d27b79878b7..32e4e5686f24a 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -3049,9 +3049,10 @@ ZEND_API zend_bool zend_is_callable_ex(zval *callable, zval *object_ptr, uint ch return 0; } - fcc->calling_scope = Z_OBJCE_PP(obj); /* TBFixed: what if it's overloaded? */ - fcc->object_ptr = *obj; + fcc->calling_scope = instanceof_function(Z_OBJCE_PP(obj), EG(scope) TSRMLS_CC) + ? EG(scope) + : Z_OBJCE_PP(obj); if (callable_name) { char *ptr; @@ -3107,7 +3108,7 @@ ZEND_API zend_bool zend_is_callable_ex(zval *callable, zval *object_ptr, uint ch if (Z_OBJ_HANDLER_P(callable, get_closure) && Z_OBJ_HANDLER_P(callable, get_closure)(callable, &fcc->calling_scope, &fcc->function_handler, &fcc->object_ptr TSRMLS_CC) == SUCCESS) { fcc->called_scope = fcc->calling_scope; if (callable_name) { - zend_class_entry *ce = Z_OBJCE_P(callable); /* TBFixed: what if it's overloaded? */ + zend_class_entry *ce = Z_OBJCE_P(callable); *callable_name_len = ce->name_length + sizeof("::__invoke") - 1; *callable_name = emalloc(*callable_name_len + 1); diff --git a/ext/standard/tests/general_functions/callbacks_001.phpt b/ext/standard/tests/general_functions/callbacks_001.phpt index a58f19d932b8e..8c3a2209bfbb6 100644 --- a/ext/standard/tests/general_functions/callbacks_001.phpt +++ b/ext/standard/tests/general_functions/callbacks_001.phpt @@ -78,6 +78,21 @@ echo "===FOREIGN===\n"; $o = new P; $o->test(); +echo "===WITHOUT SCOPE===\n"; +function call($cb) { + echo join('|', $cb) . "\n"; + call_user_func($cb); +} +call(array($o, 'who')); +call(array($o, 'O::who')); +call(array($o, 'P::who')); +call(array($o, 'B::who')); +call(array($o, 'parent::who')); + +call(array('parent', 'who')); +call(array('C', 'parent::who')); +call(array('C', 'who')); + ?> ===DONE=== --EXPECTF-- @@ -105,4 +120,23 @@ O $this|B::who Warning: call_user_func() expects parameter 1 to be a valid callback, class 'P' is not a subclass of 'B' in %s on line %d -===DONE=== +===WITHOUT SCOPE=== +$this|who +P +$this|O::who +O +$this|P::who +P +$this|B::who + +Warning: call_user_func() expects parameter 1 to be a valid callback, class 'P' is not a subclass of 'B' in %s on line %d +$this|parent::who +O +parent|who + +Warning: call_user_func() expects parameter 1 to be a valid callback, cannot access parent:: when no class scope is active in %s on line %d +C|parent::who +B +C|who +B +===DONE=== \ No newline at end of file