Skip to content

ReflectionParameter::__toString should return FQCN symbols #9447

Closed

Description

@nicolas-grekas

Description

The following code:

namespace App;

class Foo
{
    public function baz(string $arg = new Foo() . Foo::BAR)
    {
    }
}

$r = new \ReflectionMethod(Foo::class, 'baz');

echo $r->getParameters()[0];

Resulted in this output:

Parameter #0 [ <optional> string $arg = new \App\Foo() . App\Foo::BAR ]

But I expected this output instead:

Parameter #0 [ <optional> string $arg = new \App\Foo() . \App\Foo::BAR ]

Originally reported at doctrine/common#983

PHP Version

8.1+

Operating System

No response

Activity

  1. Girgias commented on Aug 30, 2022

    @Girgias
    Member

    This also applies to PHP 8.0: https://3v4l.org/fVZOh

  2. self-assigned this
    on Sep 1, 2022
  3. iluuu1994 commented on Sep 1, 2022

    @iluuu1994
    Member

    Worth noting the new case only works by chance because the fetch type overrides the ZEND_NAME_NOT_FQ flag:
    https://3v4l.org/JXNPW

    namespace App;
    
    class Foo {
        public function bar(string $p = new parent)
        {
        }
    }
    
    $r = new \ReflectionMethod(Foo::class, 'bar');
    echo $r->getParameters()[0];

    Parameter #0 [ string $p = new namespace\parent() ]

  4. added 2 commits that reference this issue on Sep 1, 2022
    fa0ef88
    2cfb028
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions