|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70220 Array to string conversion on dynamic method call
Submitted: 2015-08-09 14:00 UTC Modified: 2015-08-09 14:31 UTC
From: sebrogier at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: Scripting Engine problem
PHP Version: 7.0.0beta3 OS:
Private report: No CVE-ID: None
 [2015-08-09 14:00 UTC] sebrogier at gmail dot com
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:

class Foo {
    public function bar() {  echo 'a'; }

$foo = new Foo();
foreach ([['bar']] as $test) {
    $method = $test[0];
    // displays "a" ==> success

foreach ([['bar']] as $test) {
    // Notice "Array to string conversion" followed by
    // "Function name must be a string"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-08-09 14:24 UTC]
-Status: Open +Status: Not a bug -Package: Reproducible crash +Package: Scripting Engine problem -Assigned To: +Assigned To: cmb
 [2015-08-09 14:24 UTC]
This not a bug, but rather a delibate change in PHP 7.0.0, see

Formerly `$foo->$test[0]()` was interpreted as
`$foo->{$test[0]}()', but as of PHP 7 as `($foo->$test)[0]()`.

See <> and <>.
 [2015-08-09 14:31 UTC] sebrogier at gmail dot com
Thanks for your answer and sorry for the useless report.
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun May 26 03:01:26 2019 UTC