php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72137 Backward variable handling ain't working accourding to doc
Submitted: 2016-05-02 07:53 UTC Modified: 2016-05-02 08:04 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: dutchprogrammer at gmail dot com Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: 7.0.6 OS: centos 7 (linux)
Private report: No CVE-ID: None
 [2016-05-02 07:53 UTC] dutchprogrammer at gmail dot com
Description:
------------
Accourding to the 'Changes to variable handling' (http://php.net/manual/en/migration70.incompatible.php#migration70.incompatible.variable-handling.indirect), arrays that i want to pass as function name i have to write as ($foo->$bar)['baz']()

In my case i have an api that check the url wich class and function needed to be loaded for example (in short):
url: users/getData

i split the url with explode on '/' and then pass the second url key [1] as a function:
$url = 'users/getData';
$urlSplit = explode('/', $url, 2);
($class->$urlSplit)[1]($param1, $params2);

It's weird to write it like this but this ain’t working.

I need to save the function to a new variable to fix it like this:
$function = $urlSplit[1];
$class->$function($param1, $params2);













Test script:
---------------
Explained in the description above


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-05-02 08:04 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2016-05-02 08:04 UTC] requinix@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

> Code that used the old right-to-left evaluation order must be rewritten to
> explicitly use that evaluation order with curly braces (see the above middle
> column).

$foo->{$bar['baz']}()

$class->{$urlSplit[1]}($param1, $params2);
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 07:01:28 2024 UTC