Skip to content

Stdlib: ReflectionParameter — attributes + type + default value parity (ext/reflection/php_reflection.c) #4385

Description

@PurHur

Category

stdlib · php-src-strict

Problem

ReflectionParameter parity gaps vs Zend: parameter attributes, type information (nullable / union / intersection / DNF), and default value introspection must match php-src. PHPUnit, DI containers, and this compiler's own reflection tests depend on ReflectionParameter::getAttributes(), getType(), isDefaultValueAvailable(), and getDefaultValue().

Current VM reflection returns incomplete metadata for parameters (attributes on params were deferred from the initial attribute rollout).

php-src reference

Repro (failure today)

<?php
declare(strict_types=1);

#[Attribute]
final class A {
    public function __construct(public string $x) {}
}

class C {
    public function f(#[A('p')] ?int $p = 42, string ...$rest) {}
}

$rm = new ReflectionMethod(C::class, 'f');
$rp = $rm->getParameters()[0];

echo $rp->getName(), "\n";
echo ($rp->hasType() ? $rp->getType()->__toString() : 'no-type'), "\n";
echo ($rp->isDefaultValueAvailable() ? 'has-default' : 'no-default'), "\n";
if ($rp->isDefaultValueAvailable()) {
    var_export($rp->getDefaultValue());
    echo "\n";
}
$attrs = $rp->getAttributes(A::class);
echo count($attrs), "\n";
if ($attrs) {
    $inst = $attrs[0]->newInstance();
    echo $inst->x, "\n";
}
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php repro.php
php bin/vm.php repro.php
'
Check Zend VM today
getName() p may work
getType() ?int incomplete
getDefaultValue() 42 missing/wrong
getAttributes(A::class) count 1, x=p count 0 ❌

Scope (PHP-in-PHP)

Path Work
ext/standard/VmReflection.php ReflectionParameter methods
lib/VM/BuiltinClasses.php arg metadata from compile table
lib/VM/ReflectionSupport.php attribute materialization for ZEND_ATTRIBUTE_TARGET_PARAMETER
script/capability-matrix.php reflection rows

Done when (php-src-strict)

  • Repro output matches Zend on all four checks above
  • Variadic ...$rest parameter: isVariadic() true; no false default
  • Union/intersection/DNF parameter types stringify like Zend
  • test/compliance/cases/stdlib/reflection_parameter_attributes.phpt green
  • ./script/ci-fast.sh --filter reflection_parameter green

Related

Activity

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

    area:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions