summaryrefslogtreecommitdiff
path: root/ext/standard/basic_functions.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/standard/basic_functions.c')
-rw-r--r--ext/standard/basic_functions.c60
1 files changed, 46 insertions, 14 deletions
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c
index 43b3b1407..3d61f3d0c 100644
--- a/ext/standard/basic_functions.c
+++ b/ext/standard/basic_functions.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2007 The PHP Group |
+ | Copyright (c) 1997-2008 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: basic_functions.c,v 1.725.2.31.2.66 2007/10/22 07:37:20 dmitry Exp $ */
+/* $Id: basic_functions.c,v 1.725.2.31.2.69 2008/03/20 00:55:26 dsp Exp $ */
#include "php.h"
#include "php_streams.h"
@@ -4568,10 +4568,11 @@ PHP_FUNCTION(getopt)
* in order to be on the safe side, even though it is also available
* from the symbol table.
*/
- if (zend_hash_find(HASH_OF(PG(http_globals)[TRACK_VARS_SERVER]), "argv", sizeof("argv"), (void **) &args) != FAILURE ||
- zend_hash_find(&EG(symbol_table), "argv", sizeof("argv"), (void **) &args) != FAILURE) {
+ if ((zend_hash_find(HASH_OF(PG(http_globals)[TRACK_VARS_SERVER]), "argv", sizeof("argv"), (void **) &args) != FAILURE ||
+ zend_hash_find(&EG(symbol_table), "argv", sizeof("argv"), (void **) &args) != FAILURE) && Z_TYPE_PP(args) == IS_ARRAY
+ ) {
int pos = 0;
- zval **arg;
+ zval **entry;
argc = zend_hash_num_elements(Z_ARRVAL_PP(args));
@@ -4586,8 +4587,22 @@ PHP_FUNCTION(getopt)
/* Iterate over the hash to construct the argv array. */
while (zend_hash_get_current_data(Z_ARRVAL_PP(args),
- (void **)&arg) == SUCCESS) {
- argv[pos++] = estrdup(Z_STRVAL_PP(arg));
+ (void **)&entry) == SUCCESS) {
+ zval arg, *arg_ptr = *entry;
+
+ if (Z_TYPE_PP(entry) != IS_STRING) {
+ arg = **entry;
+ zval_copy_ctor(&arg);
+ convert_to_string(&arg);
+ arg_ptr = &arg;
+ }
+
+ argv[pos++] = estrdup(Z_STRVAL_P(arg_ptr));
+
+ if (arg_ptr != *entry) {
+ zval_dtor(&arg);
+ }
+
zend_hash_move_forward(Z_ARRVAL_PP(args));
}
@@ -4605,7 +4620,7 @@ PHP_FUNCTION(getopt)
#ifdef HARTMUT_0
int len, c = zend_hash_num_elements(Z_ARRVAL_P(p_longopts));
struct option *p;
- zval **arg;
+ zval **entry;
char *name;
longopts = (struct option *)ecalloc(c+1, sizeof(struct option));
@@ -4618,10 +4633,19 @@ PHP_FUNCTION(getopt)
/* Iterate over the hash to construct the argv array. */
while (zend_hash_get_current_data(Z_ARRVAL_P(p_longopts),
- (void **)&arg) == SUCCESS) {
+ (void **)&entry) == SUCCESS) {
+ zval arg, *arg_ptr = *entry;
+
+ if (Z_TYPE_PP(entry) != IS_STRING) {
+ arg = **entry;
+ zval_copy_ctor(&arg);
+ convert_to_string(&arg);
+ arg_ptr = &arg;
+ }
+
p->has_arg = 0;
- name = estrdup(Z_STRVAL_PP(arg));
+ name = estrdup(Z_STRVAL_P(arg_ptr));
len = strlen(name);
if((len > 0) && (name[len-1] == ':')) {
p->has_arg++;
@@ -4636,6 +4660,10 @@ PHP_FUNCTION(getopt)
p->flag = NULL;
p->val = 0;
+ if (arg_ptr != *entry) {
+ zval_dtor(&arg);
+ }
+
zend_hash_move_forward(Z_ARRVAL_P(p_longopts));
p++;
}
@@ -5191,8 +5219,10 @@ PHP_FUNCTION(call_user_method)
SEPARATE_ZVAL(params[0]);
convert_to_string(*params[0]);
- if (call_user_function_ex(EG(function_table), params[1], *params[0], &retval_ptr, arg_count-2, params+2, 0, NULL TSRMLS_CC) == SUCCESS && retval_ptr) {
- COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr);
+ if (call_user_function_ex(EG(function_table), params[1], *params[0], &retval_ptr, arg_count-2, params+2, 0, NULL TSRMLS_CC) == SUCCESS) {
+ if (retval_ptr) {
+ COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr);
+ }
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call %s()", Z_STRVAL_PP(params[0]));
}
@@ -5233,8 +5263,10 @@ PHP_FUNCTION(call_user_method_array)
element++;
}
- if (call_user_function_ex(EG(function_table), obj, *method_name, &retval_ptr, num_elems, method_args, 0, NULL TSRMLS_CC) == SUCCESS && retval_ptr) {
- COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr);
+ if (call_user_function_ex(EG(function_table), obj, *method_name, &retval_ptr, num_elems, method_args, 0, NULL TSRMLS_CC) == SUCCESS) {
+ if (retval_ptr) {
+ COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr);
+ }
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call %s()", Z_STRVAL_PP(method_name));
}