Bug #76430 [Opn->Csd]: __METHOD__ inconsistent outside of method
| From: | nikic@php.net | Date: | Tue, 12 Feb 2019 16:37:55 +0000 |
| Subject: | Bug #76430 [Opn->Csd]: __METHOD__ inconsistent outside of method | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-219533@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=76430&edit=1
ID: 76430
Updated by: nikic@php.net
Reported by: nikic@php.net
Summary: __METHOD__ inconsistent outside of method
-Status: Open
+Status: Closed
Type: Bug
Package: Scripting Engine problem
PHP Version: 7.2.6
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=93641539429c41a8997016ee4a4502882b0a722e
Log: Fixed bug #76430
Previous Comments:
------------------------------------------------------------------------
[2018-06-08 09:43:20] nikic@php.net
Description:
------------
When __METHOD__ is used outside a method, but inside a class, it currently either returns the name
of the class, or the name of the wrapping function, if the class is defined inside a function.
There are three possible results that would be consistent, though I think the best one would be to
return an empty string in both cases, as we are logically not inside a method or function -- the
class declaration separates the scope.
Test script:
---------------
<?php
class Foo {
const X = __METHOD__;
}
function foo() {
class Bar {
const X = __METHOD__;
}
}
foo();
var_dump(Foo::X);
var_dump(Bar::X);
Expected result:
----------------
string(0) ""
string(0) ""
or
string(3) "Foo"
string(3) "Bar"
or
string(0) ""
string(3) "foo"
Actual result:
--------------
string(3) "Foo"
string(3) "foo"
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76430&edit=1