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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
44 - 8 = ?
Subscribe to this entry?

 
 [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: Fri Apr 26 05:01:30 2024 UTC