Req #63629 [Opn->Fbk]: New constant __ALIAS__ for trait functions to know how they were called
| From: | laruence@php.net | Date: | Wed, 28 Nov 2012 09:50:56 +0000 |
| Subject: | Req #63629 [Opn->Fbk]: New constant __ALIAS__ for trait functions to know how they were called | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-174987@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=63629&edit=1
ID: 63629
Updated by: laruence@php.net
Reported by: spamfreedave-zend at yahoo dot com
Summary: New constant __ALIAS__ for trait functions to know
how they were called
-Status: Open
+Status: Feedback
Type: Feature/Change Request
Package: *General Issues
Operating System: Mac OSX
PHP Version: 5.4.9
Block user comment: N
Private report: N
New Comment:
could you explain a little more: what i " some interesting dynamic behavior" ?
I mean , the real use case.
Previous Comments:
------------------------------------------------------------------------
[2012-11-27 18:52:27] spamfreedave-zend at yahoo dot com
Description:
------------
I would like my trait functions to know what alias (if any) was used to call them.
The idea came from discovering that you can give a trait function multiple aliases (see Test
Script).
It occurs to me that you could have some interesting dynamic behavior if the trait function was able
to determine what name (alias) was used to call it.
If possible, a new constant __ALIAS__ could be created to store this value.
Thank you for your consideration.
Test script:
---------------
<?php
trait TestTrait
{
public function test() { print __FUNCTION__ . ', ' . __ALIAS__ . "\n"; }
}
class TestClass
{
use TestTrait { test as test2; test as test1; }
}
$c = new TestClass();
$c->test1();
$c->test2();
Expected result:
----------------
test, test1
test, test2
Actual result:
--------------
test, __ALIAS__
test, __ALIAS__
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=63629&edit=1