php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73201 Cannot call a method in $objName->$arrName[$key]() form from 7.0
Submitted: 2016-09-29 03:43 UTC Modified: 2016-09-29 04:03 UTC
From: liyangdal at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 7.0.11 OS: Any
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: liyangdal at gmail dot com
New email:
PHP Version: OS:

 

 [2016-09-29 03:43 UTC] liyangdal at gmail dot com
Description:
------------
until 5.6.26, I can call a method for a object in the below form which the $value is a method in the class:

$objName->$arrName[$key]();

but from 7.0, I got error message like:

PHP Notice:  Array to string conversion in /home/xxx/test.php on line 12
PHP Notice:  Undefined property: TestClass::$Array in /home/xxx/test.php on line 12
PHP Fatal error:  Uncaught Error: Function name must be a string in /home/xxx/test.php:12
Stack trace:
#0 {main}
  thrown in /home/xxx/test.php on line 12

Test script:
---------------
<?php
class TestClass{
    function testFunc() {
        echo "a\n";
    }
}

$funcs = array( "a" => "testFunc");

$testObject = new TestClass();
$funcTag = "a";
$testObject->$funcs[$funcTag]();


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-09-29 04:03 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2016-09-29 04:03 UTC] requinix@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

The order of evaluation in situations like that has changed in PHP 7.
http://php.net/manual/en/migration70.incompatible.php#migration70.incompatible.variable-handling.indirect
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Tue Oct 06 17:00:01 2026 UTC