Skip to content

"internal error" in ReflectionParameter::getDefaultValue on Variable-length argument list #12371

Open
@divinity76

Description

@divinity76

Description

The following code:

<?php
declare(strict_types=1);
function f(...$args){
    echo "see? arguments are optional.\n";
}
f();
$ref = new ReflectionFunction('f');
var_dump($ref->getParameters()[0]->getDefaultValue());

Resulted in this output:

see? arguments are optional.

Fatal error: Uncaught ReflectionException: Internal error: Failed to retrieve the default value in /in/gHhJ2:8
Stack trace:
#0 /in/gHhJ2(8): ReflectionParameter->getDefaultValue()
#1 {main}
  thrown in /in/gHhJ2 on line 8

But I expected this output instead:

see? arguments are optional.
array(0) {
}

3v4l: https://3v4l.org/gHhJ2

PHP Version

8.2.11

Operating System

windows 10

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions