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
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

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: Tue Apr 23 18:01:34 2024 UTC