php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73326 Imported functions cannot be passed as callable parameters
Submitted: 2016-10-16 11:59 UTC Modified: 2016-10-30 04:22 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:1 (50.0%)
From: castarco at litipk dot com Assigned: cmb (profile)
Status: No Feedback Package: Reproducible crash
PHP Version: 7.0.12 OS: Ubuntu 16.04 64 bits
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2016-10-16 11:59 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-10-16 12:13 UTC] 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-18 12:04 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2016-10-18 12:04 UTC] cmb@php.net
What do you mean by "This will crash"? Is there a segfault or
something like that?
 [2016-10-30 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Dec 03 17:03:34 2021 UTC