Skip to content

Commit ac04bf5

Browse files
committed
Add new test for destructors
1 parent a58629a commit ac04bf5

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
--TEST--
2+
Test that the destructor of the cloned object is run
3+
--FILE--
4+
<?php
5+
6+
class Foo
7+
{
8+
public function __construct(
9+
public readonly int $bar
10+
) {}
11+
12+
public function __destruct()
13+
{
14+
echo "Destruct $this->bar\n";
15+
}
16+
17+
public function with()
18+
{
19+
return clone $this with {
20+
"bar" => 1,
21+
"bar" => 2,
22+
};
23+
}
24+
}
25+
26+
$foo = new Foo(0);
27+
28+
try {
29+
$foo->with();
30+
} catch (Error $e) {
31+
echo $e->getMessage() . "\n";
32+
}
33+
34+
?>
35+
--EXPECTF--
36+
Destruct 1
37+
Cannot modify readonly property Foo::$bar
38+
Destruct 0

0 commit comments

Comments
 (0)