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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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: Wed Apr 24 00:01:32 2024 UTC