Edit report at https://bugs.php.net/bug.php?id=65419&edit=1

 ID:                 65419
 Comment by:         requi...@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

Reply via email to