php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74726 Cannot call closure from static class member
Submitted: 2017-06-09 08:56 UTC Modified: 2017-06-09 13:26 UTC
From: matteo_tassinari_TM at libero dot it Assigned: cmb (profile)
Status: Not a bug Package: Scripting Engine problem
PHP Version: 7.0.20 OS: Linux
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: matteo_tassinari_TM at libero dot it
New email:
PHP Version: OS:

 

 [2017-06-09 08:56 UTC] matteo_tassinari_TM at libero dot it
Description:
------------
If you declare a closure as a static member of a class, you cannot call it directly.

Test script:
---------------
class T {
  public static $f;
}

T::$f = function() { echo "static member\n"; };
$f = function() { echo "local variable\n"; };

$f();
T::$f();

Expected result:
----------------
local variable
static member

Actual result:
--------------
local variable
Fatal error: Uncaught Error: Function name must be a string

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-06-09 13:26 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2017-06-09 13:26 UTC] cmb@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

See <https://3v4l.org/bpsFf> on one way to do it. Note that as of
PHP 7.0.0 you can also use the following:

  (T::$f)();
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 00:01:35 2025 UTC