php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69194 Variable variables using an array to call a method broken
Submitted: 2015-03-05 17:32 UTC Modified: 2015-03-05 17:39 UTC
From: donatj at gmail dot com Assigned:
Status: Not a bug Package: Variables related
PHP Version: master-Git-2015-03-05 (Git) OS: Irrelevant
Private report: No CVE-ID: None
 [2015-03-05 17:32 UTC] donatj at gmail dot com
Description:
------------
http://3v4l.org/3NKUS  

The problem is illustrated here. It is causing a number of my tests to fail in 7 using build 20150201.

Test script:
---------------
<?php

class Foo {
    function bar(){
        echo "Futbal";
    }
}

$baz = new Foo;
$qux = array("quux" => "bar");
$baz->$qux["quux"]();

Expected result:
----------------
"Futbal"

Actual result:
--------------
Notice: Array to string conversion in /in/3NKUS on line 13

Notice: Undefined property: Foo::$Array in /in/3NKUS on line 13

Fatal error: Function name must be a string in /in/3NKUS on line 13

Process exited with code 255.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-03-05 17:39 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2015-03-05 17:39 UTC] nikic@php.net
This is an intentional BC break in PHP 7, please write $baz->{$qux["quux"]}() instead.

See https://github.com/php/php-src/blob/master/UPGRADING#L27 for a summary of related changes and https://wiki.php.net/rfc/uniform_variable_syntax for detailed information.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 19:01:29 2024 UTC