php-src/ext/reflection/tests/new_in_constexpr.phpt
Nikita Popov 52d3d0d8d7 Add limited support for new in initializers
Add support for new expressions inside parameter default values,
static variable initializers, global constant initializers and
attribute arguments.

RFC: https://wiki.php.net/rfc/new_in_initializers

Closes GH-7153.
2021-07-13 14:03:20 +02:00

27 lines
503 B
PHP

--TEST--
Handling of new in constant expressions in reflection
--FILE--
<?php
function test1() {
static $x = new stdClass;
return $x;
}
$rf = new ReflectionFunction('test1');
$s = $rf->getStaticVariables();
var_dump($s['x'] === test1());
function test2($x = new stdClass) {
return $x;
}
$rf = new ReflectionFunction('test2');
$rp = $rf->getParameters()[0];
// Parameter default should *not* be the same.
var_dump($rp->getDefaultValue() !== test2());
?>
--EXPECT--
bool(true)
bool(true)