Skip to content

Commit 621598e

Browse files
committed
Fixed bug #78921
By resetting fake_scope during autoloading. We already do the same when executing destructors.
1 parent 87691e7 commit 621598e

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

Zend/tests/bug78921.phpt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
Bug #78921: When Reflection triggers class load, property visibility is incorrect
3+
--FILE--
4+
<?php
5+
6+
spl_autoload_register(function($className) {
7+
if ($className == 'PrivateStatic') {
8+
class PrivateStatic
9+
{
10+
const SOME_CONST = 13;
11+
private static $privateStaticVarArray = ['a', 'b', 'c'];
12+
private static $otherStatic;
13+
public static function init()
14+
{
15+
self::$otherStatic = self::$privateStaticVarArray;
16+
}
17+
}
18+
PrivateStatic::init();
19+
}
20+
});
21+
22+
class OtherClass
23+
{
24+
const MY_CONST = PrivateStatic::SOME_CONST;
25+
public static $prop = 'my property';
26+
}
27+
28+
$reflectionClass = new ReflectionClass('OtherClass');
29+
$reflectionProperty = $reflectionClass->getProperty('prop');
30+
$reflectionProperty->setAccessible(true);
31+
$value = $reflectionProperty->getValue();
32+
echo "Value is $value\n";
33+
34+
?>
35+
--EXPECT--
36+
Value is my property

Zend/zend_execute_API.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,7 @@ ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, const zval *k
836836
zend_string *lc_name;
837837
zend_fcall_info fcall_info;
838838
zend_fcall_info_cache fcall_cache;
839+
zend_class_entry *orig_fake_scope;
839840

840841
if (key) {
841842
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
922923
fcall_cache.called_scope = NULL;
923924
fcall_cache.object = NULL;
924925

926+
orig_fake_scope = EG(fake_scope);
927+
EG(fake_scope) = NULL;
925928
zend_exception_save();
926929
if ((zend_call_function(&fcall_info, &fcall_cache) == SUCCESS) && !EG(exception)) {
927930
ce = zend_hash_find_ptr(EG(class_table), lc_name);
928931
}
929932
zend_exception_restore();
933+
EG(fake_scope) = orig_fake_scope;
930934

931935
zval_ptr_dtor(&args[0]);
932936
zval_ptr_dtor_str(&fcall_info.function_name);

0 commit comments

Comments
 (0)