php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69694 BC: cannot use array element directly when calling a method
Submitted: 2015-05-22 20:11 UTC Modified: 2015-05-22 20:20 UTC
From: anna at foolab dot ca Assigned:
Status: Not a bug Package: *General Issues
PHP Version: master-Git-2015-05-22 (Git) OS: Debian 3.2.65
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: anna at foolab dot ca
New email:
PHP Version: OS:

 

 [2015-05-22 20:11 UTC] anna at foolab dot ca
Description:
------------
I found this issue when testing a Magento 1.9 application.

Using array elements to call a method on an object doesn't work in php7, but used to work in php5. I made a simplified example in the test script below.

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

class Item {
    public function save()
    {
        echo 'saved';
    }
}

$callback = [new Item(), 'save'];

// This works on both php5 and php7
$method = $callback[1];
$callback[0]->$method();

// This works on php5 only
$callback[0]->$callback[1]();

Expected result:
----------------
Expected "savedsaved" output.

Actual result:
--------------
saved
Notice: Array to string conversion in /var/www/test/array_function.php on line 15

Notice: Undefined property: Item::$Array in /var/www/test/array_function.php on line 15

Fatal error: Function name must be a string in /var/www/test/array_function.php on line 15

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-05-22 20:20 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2015-05-22 20:20 UTC] requinix@php.net
This was an intentional change. See the Uniform Variable Syntax RFC for more.
https://wiki.php.net/rfc/uniform_variable_syntax

By the way, $callback() works in all versions.
http://3v4l.org/9bgXD
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 04:01:30 2024 UTC