php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77295 Class 'static' not found (parent and self too)
Submitted: 2018-12-13 18:40 UTC Modified: 2021-09-02 13:27 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: dams@php.net Assigned: nikic (profile)
Status: Assigned Package: Class/Object related
PHP Version: All OS: Irrelevant
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: dams@php.net
New email:
PHP Version: OS:

 

 [2018-12-13 18:40 UTC] dams@php.net
Description:
------------
When calling dynamically a static method, with array('static', 'method'), from the right class context, PHP emits an error 'Class 'static' not found'.

Using call_user_func($method); with the same array, leads to the correct call to the method. 

The same problem applies to 'self' and 'parent'.

https://3v4l.org/VKFaQ
https://3v4l.org/0eacu
https://3v4l.org/HkFmd

Test script:
---------------
<?php

class x {   
  static function a() {
  	  // display the current class
     echo __METHOD__;
  } 

  static function b($method) {
  	  // display the current class with method a above
  	  call_user_func($method);
          // This stops with a Fatal Error
  	  $method();
  } 
}

(new x)->b(array('static', 'a'));
?>

Expected result:
----------------
x::a
x::a

Actual result:
--------------
x::a
Fatal error: Uncaught Error: Class 'static' not found

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-01-02 11:25 UTC] nikic@php.net
-Status: Open +Status: Verified -PHP Version: 7.3.0 +PHP Version: All
 [2019-01-02 11:25 UTC] nikic@php.net
Not a big fan of this, but we probably should support it for parity with call_user_func.
 [2021-09-02 13:27 UTC] nikic@php.net
https://wiki.php.net/rfc/deprecate_partially_supported_callables would resolve this inconsistency by consistently not supporting it.
 [2021-09-02 13:27 UTC] nikic@php.net
-Status: Verified +Status: Assigned -Assigned To: +Assigned To: nikic
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Oct 04 08:01:28 2024 UTC