From: account at dds dot nl
Operating system: Windows Vista
PHP version: 5.2.5
PHP Bug Type: Scripting Engine problem
Bug description: __tostring does not work when using it for calling a function
Description:
------------
When I try to use __tostring to call a function I get an error that 'the
function name must be a string'. While calling a class member with
__tostring does work.
--Steven
Reproduce code:
---------------
<?php
class test {
public $string = 'Class member named `string`.';
public function __tostring() {
return 'string';
}
public function string() {
return "This is a string from a function.";
}
}
$test = new test();
$function_name = 'string';
print $test."\n";
print $test->$test."\n";
print $test->$function_name()."\n";
print $test->$test()."\n";
?>
Expected result:
----------------
---------- PHP ----------
string
Class member named `string`.
This is a string from a function.
This is a string from a function.
Output completed (0 sec consumed)
Actual result:
--------------
---------- PHP ----------
string
Class member named `string`.
This is a string from a function.
Fatal error: Method name must be a string in C:\projects\test.php on line
18
Output completed (0 sec consumed)
--
Edit bug report at http://bugs.php.net/?id=44542&edit=1
--
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=44542&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=44542&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=44542&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=44542&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=44542&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=44542&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=44542&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=44542&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=44542&r=support
Expected behavior: http://bugs.php.net/fix.php?id=44542&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=44542&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=44542&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=44542&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=44542&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=44542&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=44542&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=44542&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=44542&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=44542&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=44542&r=mysqlcfg