]> granicus.if.org Git - php/commitdiff
Fixed bug #25359 (array_multisort() doesn't work in a function if array is global...
authorDmitry Stogov <dmitry@php.net>
Wed, 10 Aug 2005 12:02:14 +0000 (12:02 +0000)
committerDmitry Stogov <dmitry@php.net>
Wed, 10 Aug 2005 12:02:14 +0000 (12:02 +0000)
NEWS
Zend/zend_compile.c
Zend/zend_compile.h
ext/standard/basic_functions.c

diff --git a/NEWS b/NEWS
index 8b063ee90d089c197e1cb4ffd05560fe4e270f85..f19271e901e3514ba7c806eb30c4693d60644ca2 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -54,6 +54,8 @@ PHP                                                                        NEWS
 - Fixed bug #32010 (Memory leak in mssql_fetch_batch). (fmk)
 - Fixed bug #29334 (win32 mail() provides incorrect Date: header). (Jani)
 - Fixed bug #29253 (array_diff with $GLOBALS argument fails). (Dmitry)
+- Fixed bug #25359 (array_multisort() doesn't work in a function if array is
+  global or reference). (Dmitry)
 
 14 Jul 2005, PHP 5.1 Beta 3
 - Upgraded bundled SQLite library for PDO:SQLite to 3.2.2 (Ilia)
index f73c379312c48ce93b8964fad81dffe4ac50c905..0ab89a476619f79cfdf60ecc63c74a8ebf0fa612 100644 (file)
@@ -1499,7 +1499,12 @@ void zend_do_pass_param(znode *param, zend_uchar op, int offset TSRMLS_DC)
        }
 
        if (function_ptr) {
-               send_by_reference = ARG_SHOULD_BE_SENT_BY_REF(function_ptr, (zend_uint) offset) ? ZEND_ARG_SEND_BY_REF : 0;     
+               if (ARG_MAY_BE_SENT_BY_REF(function_ptr, (zend_uint) offset)) {
+                       op = (param->op_type & (IS_VAR|IS_CV))?ZEND_SEND_REF:ZEND_SEND_VAL;
+                       send_by_reference = 0;
+               } else {
+                       send_by_reference = ARG_SHOULD_BE_SENT_BY_REF(function_ptr, (zend_uint) offset) ? ZEND_ARG_SEND_BY_REF : 0;     
+               }
        } else {
                send_by_reference = 0;
        }
index 21ea82ae17f6e61885c2afcea1c39baa2142145e..b63dd8c90a308499454f6f4d6564dac1415291bb 100644 (file)
@@ -648,6 +648,10 @@ int zendlex(znode *zendlval TSRMLS_DC);
 #define ZEND_ARG_COMPILE_TIME_BOUND (1<<1)
 #define ZEND_ARG_SEND_FUNCTION (1<<2)
 
+#define ZEND_SEND_BY_VAL     0
+#define ZEND_SEND_BY_REF     1
+#define ZEND_SEND_PREFER_REF 2
+
 /* Lost In Stupid Parentheses */
 #define ARG_SHOULD_BE_SENT_BY_REF(zf, arg_num)                                                                                 \
        (                                                                                                                                                                       \
@@ -657,15 +661,31 @@ int zendlex(znode *zendlval TSRMLS_DC);
                (                                                                                                                                                               \
                        (                                                                                                                                                       \
                                arg_num<=((zend_function *) zf)->common.num_args                                                \
-                               && ((zend_function *) zf)->common.arg_info[arg_num-1].pass_by_reference \
+                               && ((zend_function *) zf)->common.arg_info[arg_num-1].pass_by_reference == ZEND_SEND_BY_REF \
                        )                                                                                                                                                       \
                ||      (                                                                                                                                                       \
                                arg_num>((zend_function *) zf)->common.num_args                                                 \
-                               && ((zend_function *) zf)->common.pass_rest_by_reference                                \
+                               && ((zend_function *) zf)->common.pass_rest_by_reference == ZEND_SEND_BY_REF                            \
                        )                                                                                                                                                       \
                )                                                                                                                                                               \
        )
 
+#define ARG_MAY_BE_SENT_BY_REF(zf, arg_num)                                                                                    \
+       (                                                                                                                                                                       \
+               zf                                                                                                                                                              \
+               && ((zend_function *) zf)->common.arg_info                                                                              \
+               &&                                                                                                                                                              \
+               (                                                                                                                                                               \
+                       (                                                                                                                                                       \
+                               arg_num<=((zend_function *) zf)->common.num_args                                                \
+                               && ((zend_function *) zf)->common.arg_info[arg_num-1].pass_by_reference == ZEND_SEND_PREFER_REF \
+                       )                                                                                                                                                       \
+               ||      (                                                                                                                                                       \
+                               arg_num>((zend_function *) zf)->common.num_args                                                 \
+                               && ((zend_function *) zf)->common.pass_rest_by_reference == ZEND_SEND_PREFER_REF                                \
+                       )                                                                                                                                                       \
+               )                                                                                                                                                               \
+       )
 
 #define ZEND_RETURN_VAL 0
 #define ZEND_RETURN_REF 1
index e5c7a67b174503269a80e24498a4899308386b20..8ebc94371e5e557951bc7d2031aadb29ac770808 100644 (file)
@@ -142,6 +142,10 @@ static
                ZEND_ARG_PASS_INFO(1)
        ZEND_END_ARG_INFO()
 
+static
+       ZEND_BEGIN_ARG_INFO(all_args_prefer_ref, ZEND_SEND_PREFER_REF)
+       ZEND_END_ARG_INFO()
+
 typedef struct _php_shutdown_function_entry {
        zval **arguments;
        int arg_count;
@@ -449,7 +453,7 @@ function_entry basic_functions[] = {
        PHP_FE(call_user_func_array,                                                                                    NULL)
        PHP_FE(call_user_method,                second_arg_force_ref)
        PHP_FE(call_user_method_array,  second_arg_force_ref)
-       PHP_FE(serialize,                                                                                                               NULL)                                                                                                                   
+       PHP_FE(serialize,                                                                                                               NULL)
        PHP_FE(unserialize,                                                                                                             NULL)
 
        PHP_FE(var_dump,                                                                                                                NULL)
@@ -762,7 +766,7 @@ function_entry basic_functions[] = {
        PHP_FE(compact,                                                                                                                 NULL)
        PHP_FE(array_fill,                                                                                                              NULL)
        PHP_FE(range,                                                                                                                   NULL)
-       PHP_FE(array_multisort,                                                                                                 NULL)
+       PHP_FE(array_multisort,                                                                                                 all_args_prefer_ref)
        PHP_FE(array_push,                              first_arg_force_ref)
        PHP_FE(array_pop,                               first_arg_force_ref)
        PHP_FE(array_shift,                             first_arg_force_ref)