From 621598eaa8063a9e76447e07f6f3c30a8baca1e0 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 13 Dec 2019 16:37:20 +0100 Subject: [PATCH] Fixed bug #78921 By resetting fake_scope during autoloading. We already do the same when executing destructors. --- Zend/tests/bug78921.phpt | 36 ++++++++++++++++++++++++++++++++++++ Zend/zend_execute_API.c | 4 ++++ 2 files changed, 40 insertions(+) create mode 100644 Zend/tests/bug78921.phpt diff --git a/Zend/tests/bug78921.phpt b/Zend/tests/bug78921.phpt new file mode 100644 index 00000000000..a3687880812 --- /dev/null +++ b/Zend/tests/bug78921.phpt @@ -0,0 +1,36 @@ +--TEST-- +Bug #78921: When Reflection triggers class load, property visibility is incorrect +--FILE-- +getProperty('prop'); +$reflectionProperty->setAccessible(true); +$value = $reflectionProperty->getValue(); +echo "Value is $value\n"; + +?> +--EXPECT-- +Value is my property diff --git a/Zend/zend_execute_API.c b/Zend/zend_execute_API.c index a551449e799..6eb9dfacee2 100644 --- a/Zend/zend_execute_API.c +++ b/Zend/zend_execute_API.c @@ -836,6 +836,7 @@ ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, const zval *k zend_string *lc_name; zend_fcall_info fcall_info; zend_fcall_info_cache fcall_cache; + zend_class_entry *orig_fake_scope; if (key) { lc_name = Z_STR_P(key); @@ -922,11 +923,14 @@ ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, const zval *k fcall_cache.called_scope = NULL; fcall_cache.object = NULL; + orig_fake_scope = EG(fake_scope); + EG(fake_scope) = NULL; zend_exception_save(); if ((zend_call_function(&fcall_info, &fcall_cache) == SUCCESS) && !EG(exception)) { ce = zend_hash_find_ptr(EG(class_table), lc_name); } zend_exception_restore(); + EG(fake_scope) = orig_fake_scope; zval_ptr_dtor(&args[0]); zval_ptr_dtor_str(&fcall_info.function_name);