Skip to content

ReflectionParameter default value throws "Failed to retrieve the default value" for trait, interface and prelude-class (Exception, ArrayObject) methods #287

Closed

Description

@blacktrs

Summary

ReflectionParameter default value throws "Failed to retrieve the default value" for trait, interface and prelude-class (Exception, ArrayObject) methods.

Repro

<?php
interface I { public function f(int $a = 5); }
trait T { public function t($z = 'a', $q = null) {} }
class C implements I { use T; public function f(int $a = 5) {} }
class MyEx extends Exception {}
class AO extends ArrayObject {}
foreach ([['C', 't'], ['I', 'f'], ['MyEx', '__construct'], ['AO', '__construct']] as [$cls, $m]) {
    foreach ((new ReflectionMethod($cls, $m))->getParameters() as $p) {
        echo $cls, '::', $m, ' ', (string)$p, "\n";
    }
}

Expected (php)

C::t Parameter #0 [ <optional> $z = 'a' ]
C::t Parameter #1 [ <optional> $q = NULL ]
I::f Parameter #0 [ <optional> int $a = 5 ]
MyEx::__construct Parameter #0 [ <optional> string $message = "" ]
MyEx::__construct Parameter #1 [ <optional> int $code = 0 ]
MyEx::__construct Parameter #2 [ <optional> ?Throwable $previous = null ]
AO::__construct Parameter #0 [ <optional> object|array $array = [] ]
AO::__construct Parameter #1 [ <optional> int $flags = 0 ]
AO::__construct Parameter #2 [ <optional> string $iteratorClass = ArrayIterator::class ]

Actual (manticore cecbe162, Darwin arm64)

C::t 
[exit code 255]
PHP Fatal error:  Uncaught ReflectionException: Internal error: Failed to retrieve the default value

Tracking

Known-bug repro: tests/aot/repro/wrong/refl_param_default_missing_factory.php — bash tests/aot/xfail.sh -k refl_param_default_missing_factory reports XFAIL while this is open and XPASS once it is fixed; then move the repro into tests/aot/cases/ and close this issue.

Activity

  1. added
    bug
    wrong-answer
    on Oct 16, 2026
  2. blacktrs commented on Oct 16, 2026

    @blacktrs
    ContributorAuthor

    Impact

    examples/symfony-app does not start with APP_ENV=dev (exit 255, PHP Fatal error: Uncaught ReflectionException: Internal error: Failed to retrieve the default value). prod works. Present since #165 (checked on 7f2be542 and b394c2dc, so not caused by #274 or #286).

    Native backtrace at the throw (lldb):

    ReflectionParameter::getDefaultValue
    ReflectionParameter::__toString
    Symfony\Component\Config\Resource\ReflectionClassResource::generateSignature
    ReflectionClassResource::computeHash / __serialize
    serialize
    ResourceCheckerConfigCache::write
    FrameworkBundle\DependencyInjection\Compiler\ContainerBuilderDebugDumpPass::process   (debug only)
    ContainerBuilder::compile  ->  App\Kernel::initializeContainer  ->  Kernel::boot
    

    The debug container dump hashes every class's reflected signature, including inherited methods, so one such parameter is enough.

    Cause

    prelude/reflection.php ReflectionParameter::isDefaultValueAvailable() reads a flag bit set from the AST ($p->default !== null), while getDefaultValue() calls the per-parameter factory __mc_pdef_<Class>__<method>_<pos>. LowerFromAst::synthAttrFactories (src/Compile/Mir/Passes/LowerFromAst.php, ~2233) synthesizes those factories only for methods in $decl->methods of non-prelude classes (if ($cd->isStruct || $cd->isPreludeClass) { continue; }). So the flag says "has a default" and the factory symbol is absent (EmitLlvmRuntime writes null) for:

    • methods imported from a trait (not in the class's own $decl->methods),
    • methods of interfaces,
    • inherited methods whose declaring class is a prelude class (Exception::__construct, ArrayObject::__construct, ...).

    Reproduced with the file above. A second, separate defect (#288): a default written self::X is evaluated in a free factory function, outside the class.

    Suggested direction

    Synthesize the default factories for every reflectable method regardless of how it reached the class (trait uses, interfaces, prelude classes), in the declaring class's scope (fixes #288 too), and make isDefaultValueAvailable() agree with the table (never report a default whose factory is missing).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugwrong-answer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions