Skip to content

Commit 7e9e093

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fixed bug #78921
2 parents 0f2cdbf + 621598e commit 7e9e093

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
@@ -890,6 +890,7 @@ ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, zend_string *
890890
zend_string *lc_name;
891891
zend_fcall_info fcall_info;
892892
zend_fcall_info_cache fcall_cache;
893+
zend_class_entry *orig_fake_scope;
893894

894895
if (key) {
895896
lc_name = key;
@@ -986,11 +987,14 @@ ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, zend_string *
986987
fcall_cache.called_scope = NULL;
987988
fcall_cache.object = NULL;
988989

990+
orig_fake_scope = EG(fake_scope);
991+
EG(fake_scope) = NULL;
989992
zend_exception_save();
990993
if ((zend_call_function(&fcall_info, &fcall_cache) == SUCCESS) && !EG(exception)) {
991994
ce = zend_hash_find_ptr(EG(class_table), lc_name);
992995
}
993996
zend_exception_restore();
997+
EG(fake_scope) = orig_fake_scope;
994998

995999
zval_ptr_dtor(&args[0]);
9961000
zval_ptr_dtor_str(&fcall_info.function_name);

0 commit comments

Comments
 (0)