Bug #69694 [Opn->Nab]: BC: cannot use array element directly when calling a method

From: Date: Fri, 22 May 2015 20:20:07 +0000
Subject: Bug #69694 [Opn->Nab]: BC: cannot use array element directly when calling a method
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-192834@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69694&edit=1 ID: 69694 Updated by: requinix@php.net Reported by: anna at foolab dot ca Summary: BC: cannot use array element directly when calling a method -Status: Open +Status: Not a bug Type: Bug Package: *General Issues Operating System: Debian 3.2.65 PHP Version: master-Git-2015-05-22 (Git) Block user comment: N Private report: N New Comment: 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 Previous Comments: ------------------------------------------------------------------------ [2015-05-22 20:11:00] 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 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=69694&edit=1

« previous php.bugs (#192834) next »