]> granicus.if.org Git - php/commitdiff
- New parameter parsing API
authorFelipe Pena <felipe@php.net>
Sat, 21 Jun 2008 02:41:27 +0000 (02:41 +0000)
committerFelipe Pena <felipe@php.net>
Sat, 21 Jun 2008 02:41:27 +0000 (02:41 +0000)
ext/reflection/php_reflection.c
ext/reflection/tests/ReflectionMethod_invoke_basic.phpt
main/main.c

index 8a671e130f5d7f2e2bc83048cd6498d4352b2367..a9c87c2d7fcac625672344972adaa5ebc33cb62d 100644 (file)
@@ -1567,9 +1567,8 @@ ZEND_METHOD(reflection_function, getStaticVariables)
 ZEND_METHOD(reflection_function, invoke)
 {
        zval *retval_ptr;
-       zval ***params;
-       int result;
-       int argc = ZEND_NUM_ARGS();
+       zval ***params = NULL;
+       int result, num_args = 0;
        zend_fcall_info fci;
        zend_fcall_info_cache fcc;
        reflection_object *intern;
@@ -1578,10 +1577,8 @@ ZEND_METHOD(reflection_function, invoke)
        METHOD_NOTSTATIC(reflection_function_ptr);
        GET_REFLECTION_OBJECT_PTR(fptr);
 
-       params = safe_emalloc(sizeof(zval **), argc, 0);
-       if (zend_get_parameters_array_ex(argc, params) == FAILURE) {
-               efree(params);
-               RETURN_FALSE;
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", &params, &num_args) == FAILURE) {
+               return;
        }
 
        fci.size = sizeof(fci);
@@ -1590,7 +1587,7 @@ ZEND_METHOD(reflection_function, invoke)
        fci.symbol_table = NULL;
        fci.object_pp = NULL;
        fci.retval_ptr_ptr = &retval_ptr;
-       fci.param_count = argc;
+       fci.param_count = num_args;
        fci.params = params;
        fci.no_separation = 1;
 
@@ -2298,23 +2295,17 @@ ZEND_METHOD(reflection_method, __toString)
 ZEND_METHOD(reflection_method, invoke)
 {
        zval *retval_ptr;
-       zval ***params;
+       zval ***params = NULL;
        zval **object_pp;
        reflection_object *intern;
        zend_function *mptr;
-       int argc = ZEND_NUM_ARGS();
-       int result;
+       int result, num_args = 0;
        zend_fcall_info fci;
        zend_fcall_info_cache fcc;
        zend_class_entry *obj_ce;
        
        METHOD_NOTSTATIC(reflection_method_ptr);
 
-       if (argc < 1) {
-               zend_error(E_WARNING, "Invoke() expects at least one parameter, none given");
-               RETURN_FALSE;
-       }
-       
        GET_REFLECTION_OBJECT_PTR(mptr);
 
        if (!(mptr->common.fn_flags & ZEND_ACC_PUBLIC) ||
@@ -2333,10 +2324,8 @@ ZEND_METHOD(reflection_method, invoke)
                return;
        }
 
-       params = safe_emalloc(sizeof(zval **), argc, 0);
-       if (zend_get_parameters_array_ex(argc, params) == FAILURE) {
-               efree(params);
-               RETURN_FALSE;
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", &params, &num_args) == FAILURE) {
+               return;
        }
        
        /* In case this is a static method, we should'nt pass an object_pp
@@ -2349,15 +2338,18 @@ ZEND_METHOD(reflection_method, invoke)
                object_pp = NULL;
                obj_ce = NULL;
        } else {
-               if ((Z_TYPE_PP(params[0]) != IS_OBJECT)) {
+               if (Z_TYPE_PP(params[0]) != IS_OBJECT) {
                        efree(params);
                        _DO_THROW("Non-object passed to Invoke()");
                        /* Returns from this function */
                }
+
                obj_ce = Z_OBJCE_PP(params[0]);
 
                if (!instanceof_function(obj_ce, mptr->common.scope TSRMLS_CC)) {
-                       efree(params);
+                       if (params) {
+                               efree(params);
+                       }
                        _DO_THROW("Given object is not an instance of the class this method was declared in");
                        /* Returns from this function */
                }
@@ -2371,8 +2363,8 @@ ZEND_METHOD(reflection_method, invoke)
        fci.symbol_table = NULL;
        fci.object_pp = object_pp;
        fci.retval_ptr_ptr = &retval_ptr;
-       fci.param_count = argc-1;
-       fci.params = params+1;
+       fci.param_count = num_args - 1;
+       fci.params = params + 1;
        fci.no_separation = 1;
 
        fcc.initialized = 1;
@@ -2382,7 +2374,9 @@ ZEND_METHOD(reflection_method, invoke)
 
        result = zend_call_function(&fci, &fcc TSRMLS_CC);
        
-       efree(params);
+       if (params) {
+               efree(params);
+       }
 
        if (result == FAILURE) {
                zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, 
@@ -3416,14 +3410,14 @@ ZEND_METHOD(reflection_class, newInstance)
        zval *retval_ptr = NULL;
        reflection_object *intern;
        zend_class_entry *ce;
-       int argc = ZEND_NUM_ARGS();
        
        METHOD_NOTSTATIC(reflection_class_ptr);
        GET_REFLECTION_OBJECT_PTR(ce);
 
        /* Run the constructor if there is one */
        if (ce->constructor) {
-               zval ***params;
+               zval ***params = NULL;
+               int num_args = 0;
                zend_fcall_info fci;
                zend_fcall_info_cache fcc;
 
@@ -3432,9 +3426,10 @@ ZEND_METHOD(reflection_class, newInstance)
                        return;
                }
 
-               params = safe_emalloc(sizeof(zval **), argc, 0);
-               if (zend_get_parameters_array_ex(argc, params) == FAILURE) {
-                       efree(params);
+               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "*", &params, &num_args) == FAILURE) {
+                       if (params) {
+                               efree(params);
+                       }
                        RETURN_FALSE;
                }
 
@@ -3446,7 +3441,7 @@ ZEND_METHOD(reflection_class, newInstance)
                fci.symbol_table = NULL;
                fci.object_pp = &return_value;
                fci.retval_ptr_ptr = &retval_ptr;
-               fci.param_count = argc;
+               fci.param_count = num_args;
                fci.params = params;
                fci.no_separation = 1;
 
@@ -3456,7 +3451,9 @@ ZEND_METHOD(reflection_class, newInstance)
                fcc.object_pp = &return_value;
 
                if (zend_call_function(&fci, &fcc TSRMLS_CC) == FAILURE) {
-                       efree(params);
+                       if (params) {
+                               efree(params);
+                       }
                        if (retval_ptr) {
                                zval_ptr_dtor(&retval_ptr);
                        }
@@ -3466,7 +3463,9 @@ ZEND_METHOD(reflection_class, newInstance)
                if (retval_ptr) {
                        zval_ptr_dtor(&retval_ptr);
                }
-               efree(params);
+               if (params) {
+                       efree(params);
+               }
        } else if (!ZEND_NUM_ARGS()) {
                object_init_ex(return_value, ce);
        } else {
index c03a510e5bfb27cbc58ce9aeb50fa7b7e077238d..cbf358c062d546a041b7673ce3fa0324f69ddf06 100644 (file)
@@ -91,8 +91,8 @@ NULL
 
 Static method:
 
-Warning: Invoke() expects at least one parameter, none given in %s on line %d
-bool(false)
+Warning: ReflectionMethod::invoke() expects at least 1 parameter, 0 given in %s on line %d
+NULL
 Called staticMethod()
 
 Notice: Undefined variable: this in %s on line %d
index 9acf6ac13af47854239a5918a82b4946668b4080..1f656eda57372112e93969d8c84b677ab75ea829 100644 (file)
@@ -1033,8 +1033,8 @@ PHP_FUNCTION(set_time_limit)
                RETURN_FALSE;
        }
 
-       if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &new_timeout) == FAILURE) {
-               WRONG_PARAM_COUNT;
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &new_timeout) == FAILURE) {
+               return;
        }
 
        convert_to_string_ex(new_timeout);