php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79419 self:: does not refer to the same class name
Submitted: 2020-03-27 08:42 UTC Modified: 2020-03-27 09:16 UTC
From: michael dot vorisek at email dot cz Assigned:
Status: Duplicate Package: Scripting Engine problem
PHP Version: 7.4.4 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: michael dot vorisek at email dot cz
New email:
PHP Version: OS:

 

 [2020-03-27 08:42 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-03-27 09:16 UTC] nikic@php.net
-Status: Open +Status: Duplicate
 [2020-03-27 09:34 UTC] michael dot vorisek at email dot cz
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"?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 01:01:28 2024 UTC