Skip to content

Commit ebeb034

Browse files
committed
fix static member access
1 parent e8d5b37 commit ebeb034

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

Zend/zend_compile.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2943,7 +2943,8 @@ static void zend_compile_inner_class_ref(znode *result, zend_ast *ast, uint32_t
29432943
}
29442944

29452945
zend_op *opline = zend_emit_op(result, ZEND_FETCH_INNER_CLASS, &outer_node, &inner_node);
2946-
opline->extended_value = zend_alloc_cache_slot();
2946+
// ensure we allocate two slots to prevent an issue with static method access
2947+
opline->extended_value = zend_alloc_cache_slots(2);
29472948
}
29482949
/* }}} */
29492950

tests/classes/inner_classes_018.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
ensure autoloading works
3+
--FILE--
4+
<?php
5+
spl_autoload_register(static function ($class_name) {
6+
require_once(__DIR__ . '/' . $class_name . '.inc');
7+
echo 'autoload(' . $class_name . ")\n";
8+
});
9+
10+
$point = new inner_classes:>Point(1, 2);
11+
echo $point->x, ' ', $point->y, "\n";
12+
?>
13+
--EXPECT--
14+
autoload(inner_classes)
15+
1 2

tests/classes/inner_classes_020.phpt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
property types
3+
--FILE--
4+
<?php
5+
6+
class Outer {
7+
public self:>Inner $inner;
8+
private class Inner {}
9+
public function test(): void {
10+
$this->inner = new self:>Inner();
11+
}
12+
}
13+
14+
$outer = new Outer();
15+
$outer->test();
16+
var_dump($outer->inner);
17+
?>
18+
--EXPECTF--
19+
Fatal error: Uncaught TypeError: Method test is public but returns a private class: Outer:>Inner in %s:%d
20+
Stack trace:
21+
#0 %s(%d): Outer::test()
22+
#1 {main}
23+
thrown in %s on line %d

tests/classes/inner_classes_021.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--TEST--

0 commit comments

Comments
 (0)