stas Fri, 18 Dec 2009 19:12:11 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=292295
Log: fix regression bug #50394: Reference argument converted to value in __call Bug: http://bugs.php.net/50394 (Open) Reference argument converted to value in __call Changed paths: A php/php-src/branches/PHP_5_2/Zend/tests/bug50394.phpt A php/php-src/branches/PHP_5_2/Zend/tests/call_with_refs.phpt U php/php-src/branches/PHP_5_2/Zend/zend_compile.h U php/php-src/branches/PHP_5_2/Zend/zend_execute_API.c U php/php-src/branches/PHP_5_2/Zend/zend_object_handlers.c A php/php-src/branches/PHP_5_3/Zend/tests/bug50394.phpt A php/php-src/branches/PHP_5_3/Zend/tests/call_with_refs.phpt U php/php-src/branches/PHP_5_3/Zend/zend_execute_API.c A php/php-src/trunk/Zend/tests/bug50394.phpt A php/php-src/trunk/Zend/tests/call_with_refs.phpt U php/php-src/trunk/Zend/zend_execute_API.c
Added: php/php-src/branches/PHP_5_2/Zend/tests/bug50394.phpt =================================================================== --- php/php-src/branches/PHP_5_2/Zend/tests/bug50394.phpt (rev 0) +++ php/php-src/branches/PHP_5_2/Zend/tests/bug50394.phpt 2009-12-18 19:12:11 UTC (rev 292295) @@ -0,0 +1,24 @@ +--TEST-- +Bug #50394: Reference argument converted to value in __call +--FILE-- +<?php +function inc( &$x ) { $x++; } + +class Proxy { + function __call( $name, $args ) { + echo "$name called!\n"; + call_user_func_array( 'inc', $args ); + } +} + +$arg = 1; +$args = array( &$arg ); +$proxy = new Proxy; +call_user_func_array( array( $proxy, 'bar' ), $args ); +call_user_func_array( array( $proxy, 'bar' ), array(&$arg) ); +var_dump($arg); +--EXPECT-- +bar called! +bar called! +int(3) + Added: php/php-src/branches/PHP_5_2/Zend/tests/call_with_refs.phpt =================================================================== --- php/php-src/branches/PHP_5_2/Zend/tests/call_with_refs.phpt (rev 0) +++ php/php-src/branches/PHP_5_2/Zend/tests/call_with_refs.phpt 2009-12-18 19:12:11 UTC (rev 292295) @@ -0,0 +1,18 @@ +--TEST-- +Check call to non-ref function with call-time refs +--FILE-- +<?php +function my_errorhandler($errno,$errormsg) { + global $my_var; + $my_var=0x12345; + echo $errormsg."\n"; + return true; +} +$oldhandler = set_error_handler("my_errorhandler"); +$my_var = str_repeat("A",64); +$data = call_user_func_array("substr_replace",array(&$my_var, new StdClass(),1)); +echo "OK!"; +--EXPECT-- +Object of class stdClass could not be converted to string +Object of class stdClass to string conversion +OK! Modified: php/php-src/branches/PHP_5_2/Zend/zend_compile.h =================================================================== --- php/php-src/branches/PHP_5_2/Zend/zend_compile.h 2009-12-18 18:41:53 UTC (rev 292294) +++ php/php-src/branches/PHP_5_2/Zend/zend_compile.h 2009-12-18 19:12:11 UTC (rev 292295) @@ -143,6 +143,10 @@ /* deprecation flag */ #define ZEND_ACC_DEPRECATED 0x40000 +/* function flag for internal user call handler __call */ +#define ZEND_ACC_CALL_VIA_HANDLER 0x200000 + + char *zend_visibility_string(zend_uint fn_flags); Modified: php/php-src/branches/PHP_5_2/Zend/zend_execute_API.c =================================================================== --- php/php-src/branches/PHP_5_2/Zend/zend_execute_API.c 2009-12-18 18:41:53 UTC (rev 292294) +++ php/php-src/branches/PHP_5_2/Zend/zend_execute_API.c 2009-12-18 19:12:11 UTC (rev 292295) @@ -922,6 +922,7 @@ zval *param; if (EX(function_state).function->type == ZEND_INTERNAL_FUNCTION + && (EX(function_state).function->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) == 0 && !ARG_SHOULD_BE_SENT_BY_REF(EX(function_state).function, i + 1) && PZVAL_IS_REF(*fci->params[i])) { SEPARATE_ZVAL(fci->params[i]); Modified: php/php-src/branches/PHP_5_2/Zend/zend_object_handlers.c =================================================================== --- php/php-src/branches/PHP_5_2/Zend/zend_object_handlers.c 2009-12-18 18:41:53 UTC (rev 292294) +++ php/php-src/branches/PHP_5_2/Zend/zend_object_handlers.c 2009-12-18 19:12:11 UTC (rev 292295) @@ -771,7 +771,7 @@ call_user_call->arg_info = NULL; call_user_call->num_args = 0; call_user_call->scope = ce; - call_user_call->fn_flags = 0; + call_user_call->fn_flags = ZEND_ACC_CALL_VIA_HANDLER; call_user_call->function_name = estrndup(method_name, method_len); call_user_call->pass_rest_by_reference = 0; call_user_call->return_reference = ZEND_RETURN_VALUE; Added: php/php-src/branches/PHP_5_3/Zend/tests/bug50394.phpt =================================================================== --- php/php-src/branches/PHP_5_3/Zend/tests/bug50394.phpt (rev 0) +++ php/php-src/branches/PHP_5_3/Zend/tests/bug50394.phpt 2009-12-18 19:12:11 UTC (rev 292295) @@ -0,0 +1,24 @@ +--TEST-- +Bug #50394: Reference argument converted to value in __call +--FILE-- +<?php +function inc( &$x ) { $x++; } + +class Proxy { + function __call( $name, $args ) { + echo "$name called!\n"; + call_user_func_array( 'inc', $args ); + } +} + +$arg = 1; +$args = array( &$arg ); +$proxy = new Proxy; +call_user_func_array( array( $proxy, 'bar' ), $args ); +call_user_func_array( array( $proxy, 'bar' ), array(&$arg) ); +var_dump($arg); +--EXPECT-- +bar called! +bar called! +int(3) + Added: php/php-src/branches/PHP_5_3/Zend/tests/call_with_refs.phpt =================================================================== --- php/php-src/branches/PHP_5_3/Zend/tests/call_with_refs.phpt (rev 0) +++ php/php-src/branches/PHP_5_3/Zend/tests/call_with_refs.phpt 2009-12-18 19:12:11 UTC (rev 292295) @@ -0,0 +1,18 @@ +--TEST-- +Check call to non-ref function with call-time refs +--FILE-- +<?php +function my_errorhandler($errno,$errormsg) { + global $my_var; + $my_var=0x12345; + echo $errormsg."\n"; + return true; +} +$oldhandler = set_error_handler("my_errorhandler"); +$my_var = str_repeat("A",64); +$data = call_user_func_array("substr_replace",array(&$my_var, new StdClass(),1)); +echo "OK!"; +--EXPECT-- +Object of class stdClass could not be converted to string +Object of class stdClass to string conversion +OK! Modified: php/php-src/branches/PHP_5_3/Zend/zend_execute_API.c =================================================================== --- php/php-src/branches/PHP_5_3/Zend/zend_execute_API.c 2009-12-18 18:41:53 UTC (rev 292294) +++ php/php-src/branches/PHP_5_3/Zend/zend_execute_API.c 2009-12-18 19:12:11 UTC (rev 292295) @@ -838,6 +838,7 @@ zval *param; if (EX(function_state).function->type == ZEND_INTERNAL_FUNCTION + && (EX(function_state).function->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) == 0 && !ARG_SHOULD_BE_SENT_BY_REF(EX(function_state).function, i + 1) && PZVAL_IS_REF(*fci->params[i])) { SEPARATE_ZVAL(fci->params[i]); Added: php/php-src/trunk/Zend/tests/bug50394.phpt =================================================================== --- php/php-src/trunk/Zend/tests/bug50394.phpt (rev 0) +++ php/php-src/trunk/Zend/tests/bug50394.phpt 2009-12-18 19:12:11 UTC (rev 292295) @@ -0,0 +1,24 @@ +--TEST-- +Bug #50394: Reference argument converted to value in __call +--FILE-- +<?php +function inc( &$x ) { $x++; } + +class Proxy { + function __call( $name, $args ) { + echo "$name called!\n"; + call_user_func_array( 'inc', $args ); + } +} + +$arg = 1; +$args = array( &$arg ); +$proxy = new Proxy; +call_user_func_array( array( $proxy, 'bar' ), $args ); +call_user_func_array( array( $proxy, 'bar' ), array(&$arg) ); +var_dump($arg); +--EXPECT-- +bar called! +bar called! +int(3) + Added: php/php-src/trunk/Zend/tests/call_with_refs.phpt =================================================================== --- php/php-src/trunk/Zend/tests/call_with_refs.phpt (rev 0) +++ php/php-src/trunk/Zend/tests/call_with_refs.phpt 2009-12-18 19:12:11 UTC (rev 292295) @@ -0,0 +1,18 @@ +--TEST-- +Check call to non-ref function with call-time refs +--FILE-- +<?php +function my_errorhandler($errno,$errormsg) { + global $my_var; + $my_var=0x12345; + echo $errormsg."\n"; + return true; +} +$oldhandler = set_error_handler("my_errorhandler"); +$my_var = str_repeat("A",64); +$data = call_user_func_array("substr_replace",array(&$my_var, new StdClass(),1)); +echo "OK!"; +--EXPECT-- +Object of class stdClass could not be converted to string +Object of class stdClass to string conversion +OK! Modified: php/php-src/trunk/Zend/zend_execute_API.c =================================================================== --- php/php-src/trunk/Zend/zend_execute_API.c 2009-12-18 18:41:53 UTC (rev 292294) +++ php/php-src/trunk/Zend/zend_execute_API.c 2009-12-18 19:12:11 UTC (rev 292295) @@ -873,6 +873,7 @@ zval *param; if (EX(function_state).function->type == ZEND_INTERNAL_FUNCTION + && (EX(function_state).function->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) == 0 && !ARG_SHOULD_BE_SENT_BY_REF(EX(function_state).function, i + 1) && PZVAL_IS_REF(*fci->params[i])) { SEPARATE_ZVAL(fci->params[i]);
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php