Bug #73326 [Opn->Fbk]: Imported functions cannot be passed as callable parameters
| From: | cmb@php.net | Date: | Tue, 18 Oct 2016 12:04:38 +0000 |
| Subject: | Bug #73326 [Opn->Fbk]: Imported functions cannot be passed as callable parameters | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-204893@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=73326&edit=1
ID: 73326
Updated by: cmb@php.net
Reported by: castarco at litipk dot com
Summary: Imported functions cannot be passed as callable
parameters
-Status: Open
+Status: Feedback
Type: Bug
Package: Reproducible crash
Operating System: Ubuntu 16.04 64 bits
PHP Version: 7.0.12
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
What do you mean by "This will crash"? Is there a segfault or
something like that?
Previous Comments:
------------------------------------------------------------------------
[2016-10-16 12:13:51] castarco at litipk dot com
In fact, the problem is not directly related with the importing mechanism. I've seen that the
same happens when the function is declared in the same file and the same namespace. The fully
qualified name has to be specified too.
This is a problem because it makes the code longer and uglier.
I think that allowing to pass the "local names" as strings is not a solution because we
don't know what the function is doing with the passed callable.
So... maybe the solution is to handle the function name as a valid parameter token, without creating
an adhoc string (nor a Closure) to reference it.
Anyway, I suspect that this bug report will be discarded :( .
------------------------------------------------------------------------
[2016-10-16 11:59:51] castarco at litipk dot com
Description:
------------
I won't provide a test script because to test this bug we need to use many files.
Assumptions:
1. I have a function placed in some file, following the PSR-4 conventions.
2. I'm using Composer, and I force the autoloading of the file where I put the functions.
3. I import it using something like:
use function MyNamespace\functionName as myLocalFunction;
4. I check that the autoload has been done, I can directly call the function without problems:
myLocalFunction($x);
5. I can pass that function as a callable, but only with its fully qualified name:
array_filter($myData, 'MyNamespace\\functionName');
6. I cannot pass that function using the "local name":
array_filter($myData, 'myLocalFunction'); // This will crash
7. Even if I don't use aliasing whilst importing the function, the crash happens too.
Actual result:
--------------
array_filter() expects parameter 2 to be a valid callback, function 'myLocalFunction' not
found or invalid function name
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=73326&edit=1