php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #77148 No mention of __FUNCTION__ being self-referential inside a closure
Submitted: 2018-11-14 04:21 UTC Modified: 2018-11-14 14:26 UTC
From: roy-orbison at devo dot net dot au Assigned: cmb (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2018-11-14 04:21 UTC] roy-orbison at devo dot net dot au
Description:
------------
---
From manual page: https://php.net/language.constants.predefined
From manual page: https://php.net/functions.anonymous
---

__FUNCTION__ seems to correctly refer to an anonymous function within itself, but there's no information on either of the above pages. Based on internet searches it wasn't always the case, but I couldn't find the changelog where it was fixed.

Does it not work 100% of the time? Is there some reason it's not officially documented?

Test script:
---------------
<?php
call_user_func(function() {
    var_dump(__FUNCTION__);
});


Actual result:
--------------
/path/to/closure-test.php:3:string '{closure}' (length=9)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-11-14 11:51 UTC] cmb@php.net
-Status: Open +Status: Verified -Assigned To: +Assigned To: cmb
 [2018-11-14 11:51 UTC] cmb@php.net
According to <https://3v4l.org/731uA>, the behavior is identical
for all PHP versions since anonymous functions have been
introduced.  I think it makes sense to document this.
 [2018-11-14 14:25 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=345983
Log: Fix #77148: No mention of __FUNCTION__ being self-referential inside a closure
 [2018-11-14 14:26 UTC] cmb@php.net
-Status: Verified +Status: Closed
 [2018-11-14 14:26 UTC] cmb@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.
 [2020-02-07 06:05 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=6f439ae86a3c09188e2274dd895ec543181ceb9f
Log: Fix #77148: No mention of __FUNCTION__ being self-referential inside a closure
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 21:00:02 2026 UTC