Home  |  Linux  | Mysql  | PHP  | XML
Date:Thu Feb  9 21:36:07 2012
Subject:Bug #61033 __FUNCTION__ doesn't report correctly in alias trait methods
Hello everyone,

I've recently came across an odd situation where __FUNCTION__ can
produce a misleading results when using traits with aliased methods, see
https://bugs.php.net/bug.php?id=61033.
<https://bugs.php.net/bug.php?id=61033>
This has been closed and I've been asked start a discussion on here if I
disagree with the ruling. The reason why I feel this should be changes
to reflect the actual called function name is that one of main uses of
the __FUNCTION__ constant it to refer back to the function that is
currently running, for the use recursive functions:

trait FooTrait {
public function foo($n) {
if ($n == 0) return;
echo $n . PHP_EOL;
$function = __FUNCTION__;
$this->$function(--$n);
}
}

class MyClass {
use FooTrait { foo as public countdown; }
public function foo() {
echo 'MyClass::foo()';
}
}

$instance = new MyClass();
$instance->countdown(3);

This example will produce running (PHP 5.4 RC7):

10
MyClass::foo()

Which as you can see is not the desired effect.

I send this email in the hope this can get the discussion under way
regarding the magic constant __FUNCTION__.

Thanks,

Marc Easen

Navigate in group php.internals at sever news.php.net
Previous Next





  
© No Copyright
You are free to use Anything, but please consult your advocate before doing so as this website
also list content from other sources which may be copyrighted.
Site Maintained by Zareef Ahmed
Powered By PHP Consultants