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: 2018-01-22 15:06 UTC
From: marcospassos dot com at gmail dot com Assigned:
Status: Open Package: Class/Object related
PHP Version: 7.2.2RC1 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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

Add a Patch

Pull Requests

Add a Pull Request

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.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Mon Feb 18 14:01:25 2019 UTC