xref: /PHP-8.2/ext/reflection/tests/bug42976.phpt (revision 960318ed)
1--TEST--
2Bug #42976 (Crash when constructor for newInstance() or newInstanceArgs() fails)
3--FILE--
4<?php
5
6Class C {
7    function __construct(&$x) {
8        $x = "x.changed";
9    }
10}
11
12$x = "x.original";
13new C($x); // OK
14var_dump($x);
15
16$rc = new ReflectionClass('C');
17$x = "x.original";
18$rc->newInstance($x); // causes crash
19var_dump($x);
20$x = "x.original";
21$rc->newInstanceArgs(array($x)); // causes crash
22var_dump($x);
23
24echo "Done\n";
25?>
26--EXPECTF--
27string(9) "x.changed"
28
29Warning: C::__construct(): Argument #1 ($x) must be passed by reference, value given in %s on line %d
30string(10) "x.original"
31
32Warning: C::__construct(): Argument #1 ($x) must be passed by reference, value given in %s on line %d
33string(10) "x.original"
34Done
35