Bug #70220 [Nab]: Array to string conversion on dynamic method call
Edit report at https://bugs.php.net/bug.php?id=70220&edit=1
ID: 70220
User updated by: sebrogier at gmail dot com
Reported by: sebrogier at gmail dot com
Summary: Array to string conversion on dynamic method call
Status: Not a bug
Type: Bug
Package: Scripting Engine problem
PHP Version: 7.0.0beta3
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Thanks for your answer and sorry for the useless report.
Previous Comments:
------------------------------------------------------------------------
[2015-08-09 14:24:03] cmb@php.net
This not a bug, but rather a delibate change in PHP 7.0.0, see
<https://wiki.php.net/rfc/uniform_variable_syntax>.
Formerly $foo->$test[0]() was interpreted as
$foo->{$test[0]}()', but as of PHP 7 as ($foo->$test)[0]()`.
See <http://3v4l.org/qdBTj> and <http://3v4l.org/8tOim>.
------------------------------------------------------------------------
[2015-08-09 14:00:33] sebrogier at gmail dot com
Description:
------------
I have an "Array to string conversion" error on the following code.
This occurs only when the method is taken directly in the array. When I use a intermediate variable,
there are no error.
Test script:
---------------
<?php
class Foo {
public function bar() { echo 'a'; }
}
$foo = new Foo();
foreach ([['bar']] as $test) {
$method = $test[0];
$foo->$method();
// displays "a" ==> success
}
foreach ([['bar']] as $test) {
$foo->$test[0]();
// Notice "Array to string conversion" followed by
// "Function name must be a string"
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70220&edit=1
Thread (3 messages)