Bug #55214 [Com]: use of __CLASS__ within trait returns trait name not class name
| From: | Jamesjerseys at 126 dot com | Date: | Mon, 29 Aug 2011 08:27:02 +0000 |
| Subject: | Bug #55214 [Com]: use of __CLASS__ within trait returns trait name not class name | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-163073@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
Comment by: Jamesjerseys at 126 dot com
Reported by: chris dot rutledge at gmail dot com
Summary: use of __CLASS__ within trait returns trait name not
class name
Status: To be documented
Type: Bug
Package: Scripting Engine problem
Operating System: Ubuntu
PHP Version: 5.4.0alpha1
Block user comment: N
Private report: N
New Comment:
http://www.wholesalenfl-jersey.com/ Wholesale NFL
Jerseys
Previous Comments:
------------------------------------------------------------------------
[2011-08-15 08:29:43] gron@php.net
Automatic comment from SVN on behalf of gron
Revision: http://svn.php.net/viewvc/?view=revision&revision=314921
Log: Addendum for patch to bug #55214: Class name was freed before method literal referring to it.
# Thanks to Felipe for catching this.
# The fix duplicates the name into the literal to avoid the dependency
------------------------------------------------------------------------
[2011-07-31 18:23:25] gron@php.net
Fixed in SVN per http://svn.php.net/viewvc?view=revision&revision=313997
Needs documentation: __CLASS__ gives now the class name in which the trait is eventually used.
------------------------------------------------------------------------
[2011-07-31 18:18:56] gron@php.net
Automatic comment from SVN on behalf of gron
Revision: http://svn.php.net/viewvc/?view=revision&revision=313997
Log: Fixed Bug #55214 use of __CLASS__ within trait returns trait name not class name [TRAITS]
[DOC]
------------------------------------------------------------------------
[2011-07-24 18:31:08] gron@php.net
Ok, updated the patch and would like to ask for a review.
This is still hacky, but now I use the literals of a function to be able to clean up the zval for
the __CLASS__ name. Thus, the memory leak should be fixed.
Think we will still need a __TRAIT__ to mirror __CLASS__ and to get the trait name itself when that
is required.
The test case is missing in the patch:
--TEST--
Bug #55214 (Use of __CLASS__ within trait returns trait name not class name)
--FILE--
<?php
trait ATrait {
public static function get_class_name() {
return __CLASS__;
}
public function get_class_name_obj() {
return __CLASS__;
}
}
class SomeClass {
use ATrait;
}
$r = SomeClass::get_class_name();
var_dump($r);
$o = new SomeClass();
$r = $o->get_class_name_obj();
var_dump($r);
?>
--EXPECT--
string(9) "SomeClass"
string(9) "SomeClass"
------------------------------------------------------------------------
[2011-07-24 18:28:16] gron@php.net
The following patch has been added/updated:
Patch Name: __CLASS__-in-traits.002.patch
Revision: 1311532096
URL: https://bugs.php.net/patch-display.php?bug=55214&patch=__CLASS__-in-traits.002.patch&revision=1311532096
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=55214
--
Edit this bug report at https://bugs.php.net/bug.php?id=55214&edit=1