From:
Operating system: Ubuntu
PHP version: 5.4.0alpha1
Package: *General Issues
Bug Type: Bug
Bug description:use of __CLASS__ within trait returns trait name not class name
Description:
------------
use of __CLASS__ within trait returns trait name not class name.
Test script:
---------------
trait Singleton {
private static $instance;
public static function Load() {
if(!isset(self::$instance)) {
$c = __CLASS__;
self::$instance = new $c;
}
return self::$instance;
}
}
class Test {
use Singleton;
private function __construct() { }
}
Test::Load();
Expected result:
----------------
Expected __CLASS__ to return the name of the class that required the trait
('Test'), so that the singleton object could be instantiated
Actual result:
--------------
__CLASS__ returned 'Singleton', this caused a Fatel error:
Fatal error: Cannot instantiate trait Singleton in
/home/dshed/public/northie/index.php on line 7
--
Edit bug report at https://bugs.php.net/bug.php?id=55214&edit=1
--
Try a snapshot (PHP 5.2):
https://bugs.php.net/fix.php?id=55214&r=trysnapshot52
Try a snapshot (PHP 5.3):
https://bugs.php.net/fix.php?id=55214&r=trysnapshot53
Try a snapshot (trunk):
https://bugs.php.net/fix.php?id=55214&r=trysnapshottrunk
Fixed in SVN:
https://bugs.php.net/fix.php?id=55214&r=fixed
Fixed in SVN and need be documented:
https://bugs.php.net/fix.php?id=55214&r=needdocs
Fixed in release:
https://bugs.php.net/fix.php?id=55214&r=alreadyfixed
Need backtrace:
https://bugs.php.net/fix.php?id=55214&r=needtrace
Need Reproduce Script:
https://bugs.php.net/fix.php?id=55214&r=needscript
Try newer version:
https://bugs.php.net/fix.php?id=55214&r=oldversion
Not developer issue:
https://bugs.php.net/fix.php?id=55214&r=support
Expected behavior:
https://bugs.php.net/fix.php?id=55214&r=notwrong
Not enough info:
https://bugs.php.net/fix.php?id=55214&r=notenoughinfo
Submitted twice:
https://bugs.php.net/fix.php?id=55214&r=submittedtwice
register_globals:
https://bugs.php.net/fix.php?id=55214&r=globals
PHP 4 support discontinued:
https://bugs.php.net/fix.php?id=55214&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=55214&r=dst
IIS Stability:
https://bugs.php.net/fix.php?id=55214&r=isapi
Install GNU Sed:
https://bugs.php.net/fix.php?id=55214&r=gnused
Floating point limitations:
https://bugs.php.net/fix.php?id=55214&r=float
No Zend Extensions:
https://bugs.php.net/fix.php?id=55214&r=nozend
MySQL Configuration Error:
https://bugs.php.net/fix.php?id=55214&r=mysqlcfg
Try a snapshot (PHP 5.4):
https://bugs.php.net/fix.php?id=55214&r=trysnapshot54