Bug #61033 [Opn]: __FUNCTION__ doesn't report correctly in alias trait methods
| From: | gron@php.net | Date: | Thu, 09 Feb 2012 20:43:18 +0000 |
| Subject: | Bug #61033 [Opn]: __FUNCTION__ doesn't report correctly in alias trait methods | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-167364@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=61033&edit=1
ID: 61033
Updated by: gron@php.net
Reported by: marc at easen dot co dot uk
Summary: __FUNCTION__ doesn't report correctly in alias trait
methods
Status: Open
Type: Bug
Package: Reflection related
Operating System: Gentoo
PHP Version: 5.4.0RC7
Block user comment: N
Private report: N
New Comment:
While it made sense to change __CLASS__ to report the using class (since a trait is
not a class), I do not think that it makes much sense to change __FUNCTION__ to do
such magic.
__FUNCTION__ referes here to the compile time name of the lexical entity the magic
constant is embedded in. Thus, it is the name you'll find in the code. (since there
is no lexical entity class, we can fall back to the using class without having to
explain to much). (And __TRAIT__ is also not changed on usage when composing
traits, it is a lexical reference).
That's what comes to my mind when thinking about this question.
I would suggest that you write a mail to the internals mailing list to start a
discussion. This might still be a controversial thing.
I will classify it as intended behavior for the moment
Thanks (and please start a discussion on the mailing list if you disagree)
Stefan
Previous Comments:
------------------------------------------------------------------------
[2012-02-09 20:23:48] marc at easen dot co dot uk
Description:
------------
The __FUNCTION__ magic constant does not report correctly in aliased methods
within traits.
When a trait function is called by it's initial name __FUNCTION__ is correct.
When it is called by it aliased name __FUNCTION__ still reports as the initial
name, but debug_backtrace() reports the aliased method name.
Test script:
---------------
<?php
trait MyTrait {
public function foo()
{
$backtrace = debug_backtrace();
echo '__FUNCTION__ = ' . __FUNCTION__ . PHP_EOL;
echo '$backtrace[0][\'function\']) = ' . $backtrace[0]['function'] .
PHP_EOL;
}
}
class MyClass {
use MyTrait { foo as public bar; }
}
$instance = new MyClass();
echo 'foo()' . PHP_EOL;
$instance->foo();
echo PHP_EOL;
echo 'bar()' . PHP_EOL;
$instance->bar();
Expected result:
----------------
foo()
__FUNCTION__ = foo
$backtrace[0]['function']) = foo
bar()
__FUNCTION__ = bar
$backtrace[0]['function']) = bar
Actual result:
--------------
foo()
__FUNCTION__ = foo
$backtrace[0]['function']) = foo
bar()
__FUNCTION__ = foo
$backtrace[0]['function']) = bar
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=61033&edit=1