Skip to content

Commit 5f5d53f

Browse files
committed
clean up a bit and check readonly
1 parent 2092910 commit 5f5d53f

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

Zend/zend_compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9199,7 +9199,7 @@ static void zend_compile_class_decl(znode *result, zend_ast *ast, bool toplevel)
91999199
decl->flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS;
92009200
}
92019201
if (decl->attr & ZEND_ACC_READONLY) {
9202-
decl->flags |= ZEND_ACC_READONLY_CLASS & ZEND_ACC_NO_DYNAMIC_PROPERTIES;
9202+
decl->flags |= ZEND_ACC_READONLY_CLASS | ZEND_ACC_NO_DYNAMIC_PROPERTIES;
92039203
}
92049204

92059205
// configure for a nested class. This should only include:

Zend/zend_execute.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,14 +1239,14 @@ static zend_always_inline bool zend_check_type_slow(
12391239
zend_class_entry *scope = zend_get_executed_scope();
12401240
if (ce->required_scope_absolute && scope != ce->required_scope) {
12411241
if (scope == NULL) {
1242-
zend_error(E_ERROR, "Private inner class %s cannot be used as a type declaration in the global scope", ce->name->val);
1242+
zend_error(E_ERROR, "Private inner class %s cannot be used as a type declaration in the global scope", ZSTR_VAL(ce->name));
12431243
}
12441244

1245-
zend_error(E_ERROR, "Private inner class %s cannot be used as a type declaration in the scope of %s", ce->name->val, scope->name->val);
1245+
zend_error(E_ERROR, "Private inner class %s cannot be used as a type declaration in the scope of %s", ZSTR_VAL(ce->name), ZSTR_VAL(scope->name));
12461246
} else if (scope == NULL) {
1247-
zend_error(E_ERROR, "Protected inner class %s cannot be used as a type declaration in the global scope", ce->name->val);
1247+
zend_error(E_ERROR, "Protected inner class %s cannot be used as a type declaration in the global scope", ZSTR_VAL(ce->name));
12481248
} else if (!instanceof_function(scope, ce->required_scope)) {
1249-
zend_error(E_ERROR, "Protected inner class %s cannot be used as a type declaration in the scope of %s", ce->name->val, scope->name->val);
1249+
zend_error(E_ERROR, "Protected inner class %s cannot be used as a type declaration in the scope of %s", ZSTR_VAL(ce->name), ZSTR_VAL(scope->name));
12501250
}
12511251
}
12521252

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
readonly should work
3+
--FILE--
4+
<?php
5+
6+
class Outer {
7+
public readonly class Inner { public function __construct(public int $t) {} }
8+
}
9+
10+
var_dump($foo = new Outer:>Inner(1));
11+
$foo->t = 42;
12+
var_dump($foo);
13+
?>
14+
--EXPECTF--
15+
object(Outer:>Inner)#1 (1) {
16+
["t"]=>
17+
int(1)
18+
}
19+
20+
Fatal error: Uncaught Error: Cannot modify readonly property Outer:>Inner::$t in %s:%d
21+
Stack trace:
22+
#0 {main}
23+
thrown in %s on line %d

0 commit comments

Comments
 (0)