[PHP-BUG] Bug #71172 [NEW]: call a class function whose name is in array
[email protected] ("php7 at photonensammler dot de")
| Newsgroups | php.bugs |
|---|---|
| Message-ID | <[email protected]> |
From: php7 at photonensammler dot de
Operating system: Windows 10
PHP version: 7.0.1
Package: Scripting Engine problem
Bug Type: Bug
Bug description:call a class function whose name is in array
Description:
------------
Calling a class function whose name is in an array, works in php 7 no
longer as in PHP 5.6.x
Test script:
---------------
<?php
class foo {
private $functions = array(
array('funcName' => 'FUNC1'),
array('funcName' => 'FUNC2'),
array('funcName' => 'FUNC3')
);
function FUNC1() {
echo 'FUNC1', PHP_EOL, PHP_EOL;
}
function FUNC2() {
echo 'FUNC2', PHP_EOL, PHP_EOL;
}
function FUNC3() {
echo 'FUNC3', PHP_EOL, PHP_EOL;
}
/** this worked only up to PHP 5.6.16 */
public function callAllFunctions() {
foreach ($this->functions as $values) {
echo 'call ', $values['funcName'], PHP_EOL;
$this->$values['funcName']();
}
}
/** this code must be used in PHP 7.x
public function callAllFunctions() {
foreach ($this->functions as $values) {
echo 'call ', $values['funcName'], PHP_EOL;
$fncName = $values['funcName'];
$this->$fncName();
}
}
*/
}
$test = new foo();
$test->callAllFunctions();
Expected result:
----------------
expected result as in PHP 5.6.16:
call FUNC1
FUNC1
call FUNC2
FUNC2
call FUNC3
FUNC3
Actual result:
--------------
result in PHP 7.0.1
call FUNC1
Notice: Array to string conversion in ....
.... foo->callAllFunctions() .....
Notice: Undefined property: foo::$Array in ...
....
....
....
--
Edit bug report at https://bugs.php.net/bug.php?id=71172&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=71172&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=71172&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=71172&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=71172&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=71172&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=71172&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=71172&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=71172&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=71172&r=support
Expected behavior: https://bugs.php.net/fix.php?id=71172&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=71172&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=71172&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=71172&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71172&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=71172&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=71172&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=71172&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=71172&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=71172&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=71172&r=mysqlcfg