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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
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

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-2020 The PHP Group
All rights reserved.
Last updated: Fri Oct 30 05:02:34 2020 UTC