Bug #70220 [Nab]: Array to string conversion on dynamic method call

From: Date: Sun, 09 Aug 2015 14:31:01 +0000
Subject: Bug #70220 [Nab]: Array to string conversion on dynamic method call
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-195055@lists.php.net to get a copy of this message
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)

« previous php.bugs (#195055) next »