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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Thu Jan 30 16:01:30 2025 UTC