php / php/php-src

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

Open
#12,371 0 comments 0 reactions 0 assignees View on GitHub

@ndossche is already working on this.

Since Oct 6, 2023.

  • #12372 by @ndossche — open
Bug Extension: reflection Status: Verified
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the supplied PHP 8.2.11 snippet and trace the ReflectionParameter::getDefaultValue() entry point for a variadic parameter. The change is complete when the call no longer throws an internal error and produces the expected empty array; an open linked pull request shows that work is already underway.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, php
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.