php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79605 ReflectionMethod reports wrong name of aliased trait method used by a class
Submitted: 2020-05-15 17:30 UTC Modified: 2020-05-15 17:47 UTC
From: ondrej at mirtes dot cz Assigned:
Status: Duplicate Package: Reflection related
PHP Version: 7.4.6 OS: Any
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ondrej at mirtes dot cz
New email:
PHP Version: OS:

 

 [2020-05-15 17:30 UTC] ondrej at mirtes dot cz
Description:
------------
ReflectionMethod reports wrong name of aliased trait method used by a class. I'd expect the same name the ReflectionMethod was fetched as (parentFooMethod).

Test script:
---------------
<?php

trait BazTrait
{

	public function fooMethod(): void
	{

	}

}

trait BarTrait
{

	use BazTrait {
		fooMethod as parentFooMethod;
	}

	public function fooMethod(): void
	{
		$this->fooMethod();
		$this->parentFooMethod();
	}

}

class Foo
{

	use BarTrait;

	public function doFoo(): void
	{
		$this->fooMethod();
		$this->parentFooMethod();
	}

}

$bar = new \ReflectionClass(BarTrait::class);
var_dump($bar->getMethod('parentFooMethod')->getName());

$foo = new \ReflectionClass(Foo::class);
var_dump($foo->hasMethod('parentFooMethod'));
var_dump($foo->getMethod('parentFooMethod')->getName());

Expected result:
----------------
string(15) "parentFooMethod"
bool(true)
string(9) "parentFooMethod"

Actual result:
--------------
string(15) "parentFooMethod"
bool(true)
string(9) "fooMethod"

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-05-15 17:47 UTC] nikic@php.net
Duplicate of bug #69180, which is fixed in PHP 8.
 [2020-05-15 17:47 UTC] nikic@php.net
-Status: Open +Status: Duplicate
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 10 11:01:28 2024 UTC