Bug #55214 [Opn]: use of __CLASS__ within trait returns trait name not class name
| From: | felipe@php.net | Date: | Fri, 15 Jul 2011 10:32:58 +0000 |
| Subject: | Bug #55214 [Opn]: use of __CLASS__ within trait returns trait name not class name | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-6883@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=55214&edit=1
ID: 55214
Updated by: felipe@php.net
Reported by: chris dot rutledge at gmail dot com
Summary: use of __CLASS__ within trait returns trait name not
class name
Status: Open
Type: Bug
-Package: *General Issues
+Package: Documentation problem
Operating System: Ubuntu
PHP Version: 5.4.0alpha1
Block user comment: N
Private report: N
New Comment:
This is the expected behavior. It just need be documented.
Previous Comments:
------------------------------------------------------------------------
[2011-07-15 06:30:34] chris dot rutledge at gmail dot com
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 this bug report at https://bugs.php.net/bug.php?id=55214&edit=1