Bug #75853 [Opn]: Unexpected fatal error invoking static method as callables
| From: | cmb@php.net | Date: | Mon, 22 Jan 2018 15:06:32 +0000 |
| Subject: | Bug #75853 [Opn]: Unexpected fatal error invoking static method as callables | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-213660@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75853&edit=1
ID: 75853
Updated by: cmb@php.net
Reported by: marcospassos dot com at gmail dot com
Summary: Unexpected fatal error invoking static method as
callables
Status: Open
Type: Bug
Package: Class/Object related
PHP Version: 7.2.2RC1
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2018-01-22 00:46:05] 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 00:40:43] 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-21 22:25:33] 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-21 19:37:57] 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 19:10:52] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75853&edit=1