Bug #77295 [Ver->Asn]: Class 'static' not found (parent and self too)

From: Date: Thu, 02 Sep 2021 13:27:25 +0000
Subject: Bug #77295 [Ver->Asn]: Class 'static' not found (parent and self too)
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-236384@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77295&edit=1

 ID:                 77295
 Updated by:         nikic@php.net
 Reported by:        dams@php.net
 Summary:            Class 'static' not found (parent and self too)
-Status:             Verified
+Status:             Assigned
 Type:               Bug
 Package:            Class/Object related
 Operating System:   Irrelevant
 PHP Version:        All
-Assigned To:        
+Assigned To:        nikic
 Block user comment: N
 Private report:     N

 New Comment:

https://wiki.php.net/rfc/deprecate_partially_supported_callables
would resolve this inconsistency by consistently not supporting it.


Previous Comments:
------------------------------------------------------------------------
[2019-01-02 11:25:08] nikic@php.net

Not a big fan of this, but we probably should support it for parity with call_user_func.

------------------------------------------------------------------------
[2018-12-13 18:40:49] 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


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=77295&edit=1


Thread (3 messages)

« previous php.bugs (#236384) next »