-
Notifications
You must be signed in to change notification settings - Fork 8k
Expand file tree
/
Copy pathcpp_reassign_after_parent.phpt
More file actions
43 lines (37 loc) · 1.02 KB
/
cpp_reassign_after_parent.phpt
File metadata and controls
43 lines (37 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
--TEST--
Promoted readonly property reassignment - child can reassign after parent::__construct()
--FILE--
<?php
// When both parent and child have CPP for the same property, the child's
// reassignment window must survive the parent constructor's exit cleanup.
class P {
public function __construct(
public readonly string $x = 'P_default',
) {
// Parent does NOT reassign
}
}
class C extends P {
public function __construct(
public readonly string $x = 'C_default',
) {
try {
parent::__construct();
} catch (Throwable $e) {
echo get_class($e), ": ", $e->getMessage(), "\n";
}
// Child should still be able to reassign its own CPP property
$this->x = 'C_reassigned';
}
}
$c = new C();
var_dump($c->x);
// Also test with multiple instances
$c2 = new C();
var_dump($c2->x);
?>
--EXPECT--
Error: Cannot modify readonly property C::$x
string(12) "C_reassigned"
Error: Cannot modify readonly property C::$x
string(12) "C_reassigned"