Bug #81611 [NEW]: ArgumentCountError when getting default value from ReflectionParameter with new
From: ondrej at mirtes dot cz
Operating system: N/A
PHP version: 8.1.0RC5
Package: Reflection related
Bug Type: Bug
Bug description:ArgumentCountError when getting default value from ReflectionParameter with new
Description:
------------
Trying to get a default value from ReflectionParameter when the default
value contains "new" leads to "Uncaught ArgumentCountError:
ReflectionParameter::__construct() expects exactly 2 arguments, 0 given"
from an internal function.
Test script:
---------------
<?php // lint >= 8.1
namespace NewInInitializers;
class Foo
{
public function doFoo(
object $test = new self()
): object
{
return $test;
}
}
class Bar extends Foo
{
}
$ref = new \ReflectionClass(Foo::class);
$params = $ref->getMethod('doFoo')->getParameters();
foreach ($params as $param) {
var_dump($param->getDefaultValue());
}
Expected result:
----------------
object(NewInInitializers\Foo)#1 (0) {
}
Actual result:
--------------
Fatal error: Uncaught ArgumentCountError:
ReflectionParameter::__construct() expects exactly 2 arguments, 0 given
in /in/aJ2qI:25
Stack trace:
#0 [internal function]: ReflectionParameter->__construct()
#1 /in/aJ2qI(25): ReflectionParameter->getDefaultValue()
#2 {main}
thrown in /in/aJ2qI on line 25
Process exited with code 255.
--
Edit bug report at https://bugs.php.net/bug.php?id=81611&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=81611&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=81611&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=81611&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=81611&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=81611&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=81611&r=support
Expected behavior: https://bugs.php.net/fix.php?id=81611&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=81611&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=81611&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=81611&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=81611&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=81611&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=81611&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=81611&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=81611&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=81611&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=81611&r=mysqlcfg
Thread (6 messages)
- ondrej at mirtes dot cz