php-src/ext/reflection/tests/bug81611.phpt
Cameron Porter 812df2bd8a Fix bug #81611
Add zend_fetch_class_with_scope() which accepts a scope to use for
self/parent, and use that during constant expression evaluation.

Closes GH-7649.
2021-11-16 14:40:06 +01:00

65 lines
1.2 KiB
PHP

--TEST--
Reflection Bug #81611 (ArgumentCountError when getting default value from ReflectionParameter with new)
--FILE--
<?php
class Bar
{
}
class Foo extends Bar
{
public function doFoo(object $test = new self()): object
{
return $test;
}
public function doBar(object $test = new parent()): object
{
return $test;
}
}
$ref = new \ReflectionClass(Foo::class);
foreach (['doFoo', 'doBar'] as $method) {
$params = $ref->getMethod($method)->getParameters();
foreach ($params as $param) {
echo "isDefaultValueAvailable:\n";
var_dump($param->isDefaultValueAvailable());
echo "isDefaultValueConstant:\n";
var_dump($param->isDefaultValueConstant());
echo "getDefaultValueConstantName:\n";
var_dump($param->getDefaultValueConstantName());
echo "getDefaultValue:\n";
var_dump($param->getDefaultValue());
echo "\n";
}
}
?>
--EXPECT--
isDefaultValueAvailable:
bool(true)
isDefaultValueConstant:
bool(false)
getDefaultValueConstantName:
NULL
getDefaultValue:
object(Foo)#2 (0) {
}
isDefaultValueAvailable:
bool(true)
isDefaultValueConstant:
bool(false)
getDefaultValueConstantName:
NULL
getDefaultValue:
object(Bar)#3 (0) {
}