Bug #69694 [NEW]: BC: cannot use array element directly when calling a method
| From: | anna at foolab dot ca | Date: | Fri, 22 May 2015 20:11:02 +0000 |
| Subject: | Bug #69694 [NEW]: BC: cannot use array element directly when calling a method | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-192833@lists.php.net to get a copy of this message | ||
From: anna at foolab dot ca
Operating system: Debian 3.2.65
PHP version: master-Git-2015-05-22 (Git)
Package: *General Issues
Bug Type: Bug
Bug description:BC: cannot use array element directly when calling a method
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 bug report at https://bugs.php.net/bug.php?id=69694&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69694&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69694&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69694&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=69694&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=69694&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=69694&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=69694&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=69694&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=69694&r=support
Expected behavior: https://bugs.php.net/fix.php?id=69694&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=69694&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=69694&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=69694&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69694&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=69694&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=69694&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=69694&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=69694&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=69694&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=69694&r=mysqlcfg