Bug->Doc #80764 [Opn->Ver]: method magic constant in closure loses class
| From: | cmb@php.net | Date: | Thu, 18 Feb 2021 11:18:35 +0000 |
| Subject: | Bug->Doc #80764 [Opn->Ver]: method magic constant in closure loses class | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-18565@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=80764&edit=1
ID: 80764
Updated by: cmb@php.net
Reported by: bernievbb at icloud dot com
Summary: method magic constant in closure loses class
-Status: Open
+Status: Verified
-Type: Bug
+Type: Documentation Problem
Package: *General Issues
Operating System: macos
PHP Version: 8.0Git-2021-02-17 (Git)
Block user comment: N
Private report: N
New Comment:
For funtions, __METHOD__ is a synonym for __FUNCTION__[1].
Anonymous functions are *functions*, so this behaves as intended,
although the documentation[2] should be improved.
[1] <https://3v4l.org/fr6E6>
[2] <https://www.php.net/manual/en/language.constants.magic.php>
Previous Comments:
------------------------------------------------------------------------
[2021-02-17 18:15:04] bernievbb at icloud dot com
Description:
------------
class and method are lost when __METHOD__ called in closure.
Test script:
---------------
<?php
namespace pdox\pal;
class test
{
function test1()
{
var_dump(__METHOD__); // string(21) "pdox\pal\test::test1"
$a = function() {return __METHOD__;};
var_dump($a()); // string(18) "pdox\pal\{closure}"
$b = fn() => __METHOD__;
var_dump($b()); // string(18) "pdox\pal\{closure}"
}
}?>
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80764&edit=1