]> granicus.if.org Git - php/commitdiff
- MFH: New parameter parsing API
authorFelipe Pena <felipe@php.net>
Wed, 23 Jul 2008 19:34:35 +0000 (19:34 +0000)
committerFelipe Pena <felipe@php.net>
Wed, 23 Jul 2008 19:34:35 +0000 (19:34 +0000)
ext/standard/assert.c
ext/standard/basic_functions.c
ext/standard/tests/assert/assert04.phpt
ext/standard/tests/assert/assert_error1.phpt
ext/standard/tests/file/magic_quotes.phpt

index cc6dd80848ee34dc169923be54568e1fce8375ed..91eacb94a9fae0d257c7cdb456736fc49dbee267 100644 (file)
@@ -148,8 +148,8 @@ PHP_FUNCTION(assert)
                RETURN_TRUE;
        }
 
-       if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &assertion) == FAILURE) {
-               WRONG_PARAM_COUNT;
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &assertion) == FAILURE) {
+               return;
        }
 
        if (Z_TYPE_PP(assertion) == IS_STRING) {
@@ -239,17 +239,16 @@ PHP_FUNCTION(assert)
    Set/get the various assert flags */
 PHP_FUNCTION(assert_options)
 {
-       zval **what, **value;
+       zval **value;
+       long what;
        int oldint;
        int ac = ZEND_NUM_ARGS();
 
-       if (ac < 1 || ac > 2 || zend_get_parameters_ex(ac, &what, &value) == FAILURE) {
-               WRONG_PARAM_COUNT;
+       if (zend_parse_parameters(ac TSRMLS_CC, "l|Z", &what, &value) == FAILURE) {
+               return;
        }
 
-       convert_to_long_ex(what);
-
-       switch (Z_LVAL_PP(what)) {
+       switch (what) {
        case ASSERT_ACTIVE:
                oldint = ASSERTG(active);
                if (ac == 2) {
@@ -305,7 +304,7 @@ PHP_FUNCTION(assert_options)
                break;
 
        default:
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown value %ld", Z_LVAL_PP(what));
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown value %ld", what);
                break;
        }
 
index deb2ef20902ce170b4b775bff692e2724e964673..131ebc3ce4dc2453f1bb573c844d432e55557b4e 100644 (file)
@@ -4940,15 +4940,13 @@ PHP_FUNCTION(get_cfg_var)
    Set the current active configuration setting of magic_quotes_runtime and return previous */
 PHP_FUNCTION(set_magic_quotes_runtime)
 {
-       zval **new_setting;
+       zend_bool new_setting;
 
-       if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &new_setting) == FAILURE) {
-               RETURN_FALSE;
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &new_setting) == FAILURE) {
+               return;
        }
 
-       convert_to_boolean_ex(new_setting);
-
-       PG(magic_quotes_runtime) = (zend_bool) Z_LVAL_PP(new_setting);
+       PG(magic_quotes_runtime) = new_setting;
        RETURN_TRUE;
 }
 /* }}} */
@@ -4986,65 +4984,17 @@ error options:
    Send an error message somewhere */
 PHP_FUNCTION(error_log)
 {
-       zval **string, **erropt = NULL, **option = NULL, **emailhead = NULL;
-       int opt_err = 0;
        char *message, *opt = NULL, *headers = NULL;
+       int message_len, opt_len, headers_len;
+       int opt_err = 0, argc = ZEND_NUM_ARGS();
+       long erropt;
 
-       switch (ZEND_NUM_ARGS()) {
-               case 1:
-                       if (zend_get_parameters_ex(1, &string) == FAILURE) {
-                               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument 1 invalid");
-                               RETURN_FALSE;
-                       }
-                       break;
-
-               case 2:
-                       if (zend_get_parameters_ex(2, &string, &erropt) == FAILURE) {
-                               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid arguments");
-                               RETURN_FALSE;
-                       }
-                       convert_to_long_ex(erropt);
-                       opt_err = Z_LVAL_PP(erropt);
-                       break;
-
-               case 3:
-                       if (zend_get_parameters_ex(3, &string, &erropt, &option) == FAILURE) {
-                               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid arguments");
-                               RETURN_FALSE;
-                       }
-                       convert_to_long_ex(erropt);
-                       opt_err = Z_LVAL_PP(erropt);
-                       convert_to_string_ex(option);
-                       opt = Z_STRVAL_PP(option);
-                       break;
-
-               case 4:
-                       if (zend_get_parameters_ex (4, &string, &erropt, &option, &emailhead) == FAILURE) {
-                               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid arguments");
-                               RETURN_FALSE;
-                       }
-                       break;
-
-               default:
-                       WRONG_PARAM_COUNT;
-       }
-
-       convert_to_string_ex(string);
-       message = Z_STRVAL_PP(string);
-
-       if (erropt != NULL) {
-               convert_to_long_ex(erropt);
-               opt_err = Z_LVAL_PP(erropt);
-       }
-
-       if (option != NULL) {
-               convert_to_string_ex(option);
-               opt = Z_STRVAL_PP(option);
+       if (zend_parse_parameters(argc TSRMLS_CC, "s|lss", &message, &message_len, &erropt, &opt, &opt_len, &headers, &headers_len) == FAILURE) {
+               return;
        }
 
-       if (emailhead != NULL) {
-               convert_to_string_ex(emailhead);
-               headers = Z_STRVAL_PP(emailhead);
+       if (argc > 1) {
+               opt_err = erropt;
        }
 
        if (_php_error_log(opt_err, message, opt, headers TSRMLS_CC) == FAILURE) {
index 43028ad3aa11caf1feaa11220c0cc127cdf245f3..4e0e6af816a72e275cf225b770ae278e89b830c4 100644 (file)
@@ -30,11 +30,11 @@ echo "not reached\n";
  
 ?>
 --EXPECTF--
-Warning: Wrong parameter count for assert() in %s on line %d
+Warning: assert() expects exactly 1 parameter, 2 given in %s on line %d
 
-Warning: Wrong parameter count for assert_options() in %s on line %d
+Warning: assert_options() expects at most 2 parameters, 3 given in %s on line %d
 
-Warning: assert_options(): Unknown value 0 in %s on line %d
+Warning: assert_options() expects parameter 1 to be long, string given in %s on line %d
 
 Warning: assert(): Assertion failed in %s on line %d
 
index 992b81e7c4126cc6aec7b71c791a4a8c8fd60efc..6211f1c918b1629377b5c20e2e1d738864e90716 100644 (file)
@@ -34,11 +34,11 @@ var_dump($r2=assert($sa,1));
 //Catch recoverable error with handler
 var_dump($rc=assert('aa=sd+as+safsafasfaçsafçsafç'));
 --EXPECTF--
-Warning: Wrong parameter count for assert_options() in %s on line 14
+Warning: assert_options() expects at most 2 parameters, 3 given in %s on line %d
 NULL
 
-Warning: assert_options(): Unknown value 0 in %s on line 18
-bool(false)
+Warning: assert_options() expects parameter 1 to be long, string given in %s on line %d
+NULL
 
-Warning: Wrong parameter count for assert() in %s on line 22
+Warning: assert() expects exactly 1 parameter, 2 given in %s on line %d
 NULL
index 29dc9310789b58e6228f297029f7525e328bfca1..0f42cd7c8792545a2f6e5d372a436745b65f8c44 100644 (file)
@@ -69,7 +69,9 @@ Deprecated: Function set_magic_quotes_runtime() is deprecated in %s on line %d
 bool(true)
 
 Deprecated: Function set_magic_quotes_runtime() is deprecated in %s on line %d
-bool(false)
+
+Warning: set_magic_quotes_runtime() expects exactly 1 parameter, 0 given in %s on line %d
+NULL
 int(0)
 string(27) "some'content'here"and}there"
 Done