diff --git a/NEWS b/NEWS index 277411332e5..31025c18c60 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,8 @@ PHP NEWS - Core: . Fixed bug #72595 (php_output_handler_append illegal write access). (cmb) + . Fixed bug #66719 (Weird behaviour when using get_called_class() with + call_user_func()). (Nikita) - BCMath: . Fixed bug #78238 (BCMath returns "-0"). (cmb) diff --git a/Zend/tests/bug66719.phpt b/Zend/tests/bug66719.phpt new file mode 100644 index 00000000000..70785b4a784 --- /dev/null +++ b/Zend/tests/bug66719.phpt @@ -0,0 +1,43 @@ +--TEST-- +Bug #66719: Weird behaviour when using get_called_class() with call_user_func() +--FILE-- + +--EXPECT-- +string(1) "B" +string(1) "A" +string(1) "A" +string(1) "B" +string(1) "A" +string(1) "A" diff --git a/Zend/zend_API.c b/Zend/zend_API.c index de03cf5656e..ac1f09b2304 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -2922,6 +2922,9 @@ static int zend_is_callable_check_class(zend_string *name, zend_class_entry *sco if (error) *error = estrdup("cannot access self:: when no class scope is active"); } else { fcc->called_scope = zend_get_called_scope(EG(current_execute_data)); + if (!fcc->called_scope || !instanceof_function(fcc->called_scope, scope)) { + fcc->called_scope = scope; + } fcc->calling_scope = scope; if (!fcc->object) { fcc->object = zend_get_this_object(EG(current_execute_data)); @@ -2935,6 +2938,9 @@ static int zend_is_callable_check_class(zend_string *name, zend_class_entry *sco if (error) *error = estrdup("cannot access parent:: when current class scope has no parent"); } else { fcc->called_scope = zend_get_called_scope(EG(current_execute_data)); + if (!fcc->called_scope || !instanceof_function(fcc->called_scope, scope->parent)) { + fcc->called_scope = scope->parent; + } fcc->calling_scope = scope->parent; if (!fcc->object) { fcc->object = zend_get_this_object(EG(current_execute_data));