php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77851 __CLASS__ empty inside function inside class
Submitted: 2019-04-05 04:56 UTC Modified: 2019-04-05 07:28 UTC
From: requinix@php.net Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: master-Git-2019-04-05 (Git) OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: requinix@php.net
New email:
PHP Version: OS:

 

 [2019-04-05 04:56 UTC] requinix@php.net
Description:
------------
In PHP 5-7.3, using __CLASS__ inside a function defined inside a class would give the name of the containing class. Also true for anonymous classes. https://3v4l.org/uVcPi

In 7.4 and master it is an empty string.

Test script:
---------------
<?php

class Example {

    public function __construct() {

        function example() {
            var_dump(__CLASS__);
        }

    }

}

new Example();
example();

?>

Expected result:
----------------
string(7) "Example"

Actual result:
--------------
string(0) ""

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-04-05 07:28 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2019-04-05 07:28 UTC] nikic@php.net
This is an intentional change from bug #76430. A function defined inside a class has no relation to the class it is defined in. Placing the function definition inside or outside the class should have no impact on behavior.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 18:02:40 2024 UTC