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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
26 + 27 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Fri May 03 23:01:30 2024 UTC