1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 08:12:21 +01:00
Files
archived-php-src/ext/reflection/tests/ReflectionParameter_new_initializer.phpt
Nikita Popov f34114b1fb Export AST for default value strings in reflection
When dumping default values in ReflectionXXX::__toString(), for
expression initializers print the AST export instead of trying to
evaluate the expression. With the introduction of "new in
initializers" the result of the evaluation will commonly not be
printable at all, and "__toString" will throw an exception, which
is not particularly useful. Using the AST export also provides more
information on how the parameter was originally declared, e.g. it
preserves the fact that a certain constant was used.

Closes GH-7540.
2021-10-01 16:13:35 +02:00

18 lines
433 B
PHP

--TEST--
ReflectionParameter::__toString() with new initializer
--FILE--
<?php
function test(
$p1 = new stdClass,
$p2 = new SomeClass(new With, some: new Parameters)
) {}
echo new ReflectionParameter('test', 'p1'), "\n";
echo new ReflectionParameter('test', 'p2'), "\n";
?>
--EXPECT--
Parameter #0 [ <optional> $p1 = new \stdClass() ]
Parameter #1 [ <optional> $p2 = new \SomeClass(new \With(), some: new \Parameters()) ]