php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #47161 Dereferencing for array/function access
Submitted: 2009-01-20 09:08 UTC Modified: 2014-10-12 14:42 UTC
Votes:10
Avg. Score:4.4 ± 1.2
Reproduced:5 of 6 (83.3%)
Same Version:5 (100.0%)
Same OS:5 (100.0%)
From: a at b dot c dot de Assigned: nikic (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.3.0alpha3 OS: Windows (irrelevant)
Private report: No CVE-ID: None
 [2009-01-20 09:08 UTC] a at b dot c dot de
Description:
------------
See Bug #23022.

Since we can have arrays that contain arrays, arrays that contain functions, functions that return arrays and functions return functions;

and since both arrays and functions effectively define mappings between their arguments/indices and their values;

and since we can already dereference array accesses into higher dimensions (i.e., we can write $foo[1][2]);

I would like to be able to do the same thing with the other three cases. The bug cited above asks for $foo(1)[2]; I'd like to add a request for $foo[1](2) and $foo(1)(2).

Please, sir: can we have these?

Reproduce code:
---------------
<?php
$func = function($a) {
    return function($b)use($a) {
        return $a+$b;
    };
};

echo $func(5)(3);
?>

Expected result:
----------------
8

Actual result:
--------------
Parse error: syntax error, unexpected '(', expecting ',' or ';' in C:\test.php on line 9

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-01-20 09:17 UTC] a at b dot c dot de
Perhaps I should just add....
although I reference Bug #23022, I'm not asking for this to be over _arbitrary_ expressions, only arrays and callables. I don't want this language turning into Perl :)
 [2011-04-08 20:46 UTC] jani@php.net
-Package: Feature/Change Request +Package: Scripting Engine problem
 [2014-10-12 14:42 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2014-10-12 14:42 UTC] nikic@php.net
Supported in PHP 7.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 19:01:28 2024 UTC