php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: sebrogier at gmail dot com
New email:
PHP Version: OS:

 

 [2015-08-09 14:00 UTC] 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"
}



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-08-09 14:24 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Package: Reproducible crash +Package: Scripting Engine problem -Assigned To: +Assigned To: cmb
 [2015-08-09 14:24 UTC] 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:31 UTC] sebrogier at gmail dot com
Thanks for your answer and sorry for the useless report.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 17:01:58 2024 UTC