From: Nikita Popov Date: Wed, 10 Jun 2020 07:55:50 +0000 (+0200) Subject: Fix called scope assignment in autoloader X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=097043db2a0d113f89bd26c6f1d7a976d83951a8;p=php Fix called scope assignment in autoloader We should use the scope specified in the spl_autoload_register() call, not whatever LSB scope just so happens to be active at the time of the autoloader call. --- diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index f55e337ab2..4e49141555 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -403,7 +403,6 @@ static zend_class_entry *spl_perform_autoload(zend_string *class_name, zend_stri zval params[1]; zval retval; zend_string *func_name; - zend_class_entry *called_scope = zend_get_called_scope(EG(current_execute_data)); fci.size = sizeof(fci); fci.retval = &retval; @@ -431,13 +430,7 @@ static zend_class_entry *spl_perform_autoload(zend_string *class_name, zend_stri if (Z_ISUNDEF(alfi->obj)) { fci.object = NULL; fcic.object = NULL; - if (alfi->ce && - (!called_scope || - !instanceof_function(called_scope, alfi->ce))) { - fcic.called_scope = alfi->ce; - } else { - fcic.called_scope = called_scope; - } + fcic.called_scope = alfi->ce; } else { fci.object = Z_OBJ(alfi->obj); fcic.object = Z_OBJ(alfi->obj); diff --git a/ext/spl/tests/spl_autoload_called_scope.phpt b/ext/spl/tests/spl_autoload_called_scope.phpt new file mode 100644 index 0000000000..23f2e84d95 --- /dev/null +++ b/ext/spl/tests/spl_autoload_called_scope.phpt @@ -0,0 +1,33 @@ +--TEST-- +SPL autoloader should not do anything magic with called scope +--FILE-- + +--EXPECT-- +self=Test, static=Test +self=Test, static=Test2