ID: 44542 Comment by: php at xuefeng dot org Reported By: account at dds dot nl Status: Open Bug Type: Scripting Engine problem Operating System: Windows Vista PHP Version: 5.2.5 New Comment:
try this patch. Index: zend_vm_execute.h =================================================================== RCS file: /repository/ZendEngine2/zend_vm_execute.h,v retrieving revision 1.62.2.30.2.49.2.45 diff -u -r1.62.2.30.2.49.2.45 zend_vm_execute.h --- zend_vm_execute.h 28 Mar 2008 14:34:59 -0000 1.62.2.30.2.49.2.45 +++ zend_vm_execute.h 30 Mar 2008 15:54:50 -0000 @@ -28885,6 +28885,7 @@ { zend_op *opline = EX(opline); zval *function_name; + zval *name_is_object_method; char *function_name_strval; int function_name_strlen; @@ -28893,6 +28894,13 @@ function_name = _get_zval_ptr_cv(&opline->op2, EX(Ts), BP_VAR_R TSRMLS_CC); + if (Z_TYPE_P(function_name) == IS_OBJECT && Z_OBJ_HT_P(function_name)->get_method != NULL) { + ALLOC_INIT_ZVAL(name_is_object_method); + if (zend_std_cast_object_tostring(function_name, name_is_object_method, IS_STRING TSRMLS_CC) == SUCCESS) { + function_name = name_is_object_method; + } + } + if (Z_TYPE_P(function_name)!=IS_STRING) { zend_error_noreturn(E_ERROR, "Method name must be a string"); } Previous Comments: ------------------------------------------------------------------------ [2008-03-26 22:24:22] account at dds dot nl 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 this bug report at http://bugs.php.net/?id=44542&edit=1