php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75853 Unexpected fatal error invoking static method as callables
Submitted: 2018-01-21 19:10 UTC Modified: 2021-09-02 13:26 UTC
From: marcospassos dot com at gmail dot com Assigned: nikic (profile)
Status: Assigned Package: Class/Object related
PHP Version: 7.2.2RC1 OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: marcospassos dot com at gmail dot com
New email:
PHP Version: OS:

 

 [2018-01-21 19:10 UTC] marcospassos dot com at gmail dot com
Description:
------------
An unrecoverable error occurs when a static method is called as a callable, in the form of [ClassName::class, 'parent::staticMethod'], which is a perfectly valid form of callable. The same does not occur invoking the callable through call_user_func, call_user_func_array or ReflectionMethod::invoke.

Test script:
---------------
https://3v4l.org/pdTUN

Expected result:
----------------
foo


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-01-21 19:37 UTC] levim@php.net
This is one of the times I'm want to see some rationale as to why the bug is with `callable` and not with everything else. You are statically using child's symbol but statically referring to the parent method? If it was dynamic there *might* be a use-case for that but at least directly as written I don't see the value. Is there some use I'm missing?
 [2018-01-21 22:25 UTC] marcospassos dot com at gmail dot com
I can't see any real use case for this. However, my point is that type-hinting against a callable should ensure that the argument is a function/method, so there is a problem in the pseudo-type checking mechanism indeed.
 [2018-01-22 00:40 UTC] danack@php.net
> which is a perfectly valid form of callable.

Other than, "it kind of works some of the time", what's the justification for saying that it's a valid form of callable? i.e. is it in the manual anywhere?
 [2018-01-22 00:46 UTC] marcospassos dot com at gmail dot com
From manual: http://php.net/manual/en/language.types.callable.php


// Type 5: Relative static class method call (As of PHP 5.3.0)
class A {
    public static function who() {
        echo "A\n";
    }
}

class B extends A {
    public static function who() {
        echo "B\n";
    }
}

call_user_func(array('B', 'parent::who')); // A
 [2018-01-22 15:06 UTC] cmb@php.net
Also note that not only `parent::` is_callable() , but actually
any parent class of the class designated by the first array
element. E.g. <https://3v4l.org/QULq6>.  In my opionion that's
rather dubious, but we may not be able to change this for BC
reasons.
 [2021-09-02 13:26 UTC] nikic@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: nikic
 [2021-09-02 13:26 UTC] nikic@php.net
https://wiki.php.net/rfc/deprecate_partially_supported_callables would resolve this inconsistency by dropping support.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Nov 04 14:01:28 2024 UTC