Skip to content

Commit bb30fe9

Browse files
committed
Fixed bug #78868 (Calling __autoload() with incorrect EG(fake_scope) value)
1 parent e1da72b commit bb30fe9

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ PHP NEWS
55
- Core:
66
. Fixed bug #78787 (Segfault with trait overriding inherited private shadow
77
property). (Nikita)
8+
. Fixed bug #78868 (Calling __autoload() with incorrect EG(fake_scope) value).
9+
(Antony Dovgal, Dmitry)
810

911
- GD:
1012
. Fixed bug #78849 (GD build broken with -D SIGNED_COMPARE_SLOW). (cmb)

Zend/tests/bug78868.phpt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
Bug #78868: Calling __autoload() with incorrect EG(fake_scope) value
3+
--FILE--
4+
<?php
5+
class C {
6+
private $private = 1;
7+
8+
function foo() {
9+
$this->private++; //fails with EG(fake_scope) != NULL && EG(fake_scope) != "C"
10+
}
11+
}
12+
13+
class A {
14+
static $foo = B::foo; //not resolved on include()
15+
}
16+
17+
function main_autoload($class_name) {
18+
$c = new C;
19+
$c->foo();
20+
//doesn't affect the error
21+
eval("class B {const foo = 1;}");
22+
}
23+
24+
spl_autoload_register('main_autoload', false);
25+
26+
$classA = new ReflectionClass("A");
27+
$props = $classA->getProperties();
28+
$props[0]->setValue(2); //causes constant resolving, which runs autoload, all with EG(fake_scope) == "A"
29+
30+
echo "OK\n";
31+
?>
32+
--EXPECT--
33+
OK

Zend/zend_API.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4082,6 +4082,12 @@ ZEND_API int zend_update_static_property_ex(zend_class_entry *scope, zend_string
40824082
zval *property;
40834083
zend_class_entry *old_scope = EG(fake_scope);
40844084

4085+
if (UNEXPECTED(!(scope->ce_flags & ZEND_ACC_CONSTANTS_UPDATED))) {
4086+
if (UNEXPECTED(zend_update_class_constants(scope)) != SUCCESS) {
4087+
return FAILURE;
4088+
}
4089+
}
4090+
40854091
EG(fake_scope) = scope;
40864092
property = zend_std_get_static_property(scope, name, 0);
40874093
EG(fake_scope) = old_scope;

0 commit comments

Comments
 (0)