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
 [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-2021 The PHP Group
All rights reserved.
Last updated: Tue May 11 08:01:24 2021 UTC