Skip to content

Commit 72a5fde

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fixed bug #78921
2 parents 9de4f87 + 7e9e093 commit 72a5fde

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, zend_string *
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 = key;
@@ -926,11 +927,14 @@ ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, zend_string *
926927
fcall_cache.called_scope = NULL;
927928
fcall_cache.object = NULL;
928929

930+
orig_fake_scope = EG(fake_scope);
931+
EG(fake_scope) = NULL;
929932
zend_exception_save();
930933
if ((zend_call_function(&fcall_info, &fcall_cache) == SUCCESS) && !EG(exception)) {
931934
ce = zend_hash_find_ptr(EG(class_table), lc_name);
932935
}
933936
zend_exception_restore();
937+
EG(fake_scope) = orig_fake_scope;
934938

935939
zval_ptr_dtor(&args[0]);
936940
zval_ptr_dtor_str(&fcall_info.function_name);

0 commit comments

Comments
 (0)