Bug #65419 [Com]: Inside trait, self::class != __CLASS__
| From: | requinix@php.net | Date: | Thu, 08 Aug 2013 18:33:55 +0000 |
| Subject: | Bug #65419 [Com]: Inside trait, self::class != __CLASS__ | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-180807@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=65419&edit=1
ID: 65419
Comment by: requinix@php.net
Reported by: nicolas dot grekas+php at gmail dot com
Summary: Inside trait, self::class != __CLASS__
Status: Open
Type: Bug
Package: Scripting Engine problem
PHP Version: 5.5.1
Block user comment: N
Private report: N
New Comment:
The RFC was created a few weeks after 5.4.0 was released and does not specify how self::class would
work for traits. I would take that to mean the writer did not consider how it would
work for traits, rather than that traits should "inherit" the behavior for classes.
So either this is a doc bug and the ::class doc should state that it resolves to the trait itself
when used for traits (as a "::trait" syntax would be weird), or self::class is fixed so
be identical to __CLASS__. Presumably parent::class and static::class would receive similar changes.
Note for the latter: in zend_language_scanner, __CLASS__ has special handling when used inside
traits. I imagine similar logic - creating "a special __CLASS__ constant" - would be used
in
zend_do_resolve_class_name().
Previous Comments:
------------------------------------------------------------------------
[2013-08-08 08:44:05] nicolas dot grekas+php at gmail dot com
Description:
------------
The RFC for ::class name resolution as scalar say that self::class resolves the same as __CLASS__:
https://wiki.php.net/rfc/class_name_scalars#considerations
But this is not true when using traits.
Test script:
---------------
<?php
trait abc
{
static function def()
{
echo self::class, "\n";
echo __CLASS__, "\n";
}
class ghi
{
use abc;
}
ghi::def();
Expected result:
----------------
ghi
ghi
Actual result:
--------------
abc
ghi
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=65419&edit=1