Bug #79419 [Com]: self:: does not refer to the same class name

From: Date: Fri, 27 Mar 2020 09:34:08 +0000
Subject: Bug #79419 [Com]: self:: does not refer to the same class name
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-226281@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79419&edit=1

 ID:                 79419
 Comment by:         michael dot vorisek at email dot cz
 Reported by:        michael dot vorisek at email dot cz
 Summary:            self:: does not refer to the same class name
 Status:             Duplicate
 Type:               Bug
 Package:            Scripting Engine problem
 PHP Version:        7.4.4
 Block user comment: N
 Private report:     N

 New Comment:

Is there currently any possibility to access the "non-forwarding" class name, i.e. the
class name to which the "self" would reffer to without "forwarding"?


Previous Comments:
------------------------------------------------------------------------
[2020-03-27 09:16:44] nikic@php.net

Duplicate of bug #77985, see also https://wiki.php.net/rfc/lsb_parentself_forwarding.

------------------------------------------------------------------------
[2020-03-27 08:42:21] michael dot vorisek at email dot cz

Description:
------------
Please verify or provide an the intuition behind this behaviour.

This issue is critical as CS fixers are very common these days and one of the standard rule is
replace current class name with self if the name is used inside the current class definition.

Test script:
---------------
class TestParent
{
    public static function  className() {
        return static::class;
    }
    
    public static function  classNameSelf() {
        return self::className();
    }
    
    public static function  classNameExplicit() {
        return TestParent::className();
    }
}

class TestChild extends TestParent {}

print(TestChild::classNameSelf());
print("\n");
print(TestChild::classNameExplicit());

Expected result:
----------------
TestParent
TestParent

Actual result:
--------------
TestChild
TestParent


------------------------------------------------------------------------



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


Thread (3 messages)

« previous php.bugs (#226281) next »