diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 5123174569fa3..f8f6747200d7d 100755 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -30,6 +30,7 @@ #include "ext/session/php_session.h" #include "zend_exceptions.h" #include "zend_attributes.h" +#include "zend_ini.h" #include "zend_operators.h" #include "ext/standard/php_dns.h" #include "ext/standard/php_uuencode.h" @@ -1971,6 +1972,25 @@ PHP_FUNCTION(highlight_string) } /* }}} */ +/* {{{ Get interpreted size from the ini shorthand syntax */ +PHP_FUNCTION(ini_parse_quantity) +{ + zend_string *shorthand; + zend_string *errstr; + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STR(shorthand) + ZEND_PARSE_PARAMETERS_END(); + + RETVAL_LONG(zend_ini_parse_quantity(shorthand, &errstr)); + + if (errstr) { + zend_error(E_WARNING, "%s", ZSTR_VAL(errstr)); + zend_string_release(errstr); + } +} +/* }}} */ + /* {{{ Get a configuration option */ PHP_FUNCTION(ini_get) { diff --git a/ext/standard/basic_functions.stub.php b/ext/standard/basic_functions.stub.php index 5020fa4d2897f..07aefbfbef60b 100755 --- a/ext/standard/basic_functions.stub.php +++ b/ext/standard/basic_functions.stub.php @@ -488,6 +488,8 @@ function ini_alter(string $option, string|int|float|bool|null $value): string|fa function ini_restore(string $option): void {} +function ini_parse_quantity(string $shorthand): int {} + /** @refcount 1 */ function set_include_path(string $include_path): string|false {} diff --git a/ext/standard/basic_functions_arginfo.h b/ext/standard/basic_functions_arginfo.h index 0b6881a99bd17..5d17552629c2a 100644 --- a/ext/standard/basic_functions_arginfo.h +++ b/ext/standard/basic_functions_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 90093c63384f7ba56b1c4073b60219cb82843b98 */ + * Stub hash: 978052ddd734a50694d59f6e92bbf5f1cc946bd2 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_set_time_limit, 0, 1, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, seconds, IS_LONG, 0) @@ -505,6 +505,10 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ini_restore, 0, 1, IS_VOID, 0) ZEND_ARG_TYPE_INFO(0, option, IS_STRING, 0) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ini_parse_quantity, 0, 1, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, shorthand, IS_STRING, 0) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_set_include_path, 0, 1, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, include_path, IS_STRING, 0) ZEND_END_ARG_INFO() @@ -2362,6 +2366,7 @@ ZEND_FUNCTION(ini_get); ZEND_FUNCTION(ini_get_all); ZEND_FUNCTION(ini_set); ZEND_FUNCTION(ini_restore); +ZEND_FUNCTION(ini_parse_quantity); ZEND_FUNCTION(set_include_path); ZEND_FUNCTION(get_include_path); ZEND_FUNCTION(print_r); @@ -2994,6 +2999,7 @@ static const zend_function_entry ext_functions[] = { ZEND_FE(ini_set, arginfo_ini_set) ZEND_FALIAS(ini_alter, ini_set, arginfo_ini_alter) ZEND_FE(ini_restore, arginfo_ini_restore) + ZEND_FE(ini_parse_quantity, arginfo_ini_parse_quantity) ZEND_FE(set_include_path, arginfo_set_include_path) ZEND_FE(get_include_path, arginfo_get_include_path) ZEND_FE(print_r, arginfo_print_r) diff --git a/tests/basic/ini_parse_quantity_basic.phpt b/tests/basic/ini_parse_quantity_basic.phpt new file mode 100644 index 0000000000000..af9a2776f113b --- /dev/null +++ b/tests/basic/ini_parse_quantity_basic.phpt @@ -0,0 +1,36 @@ +--TEST-- +ini_parse_quantity() function - basic test for ini_parse_quantity() +--INI-- +error_reporting = E_ALL ^ E_WARNING +--FILE-- + +--EXPECT-- +-1 +-1042 +0 +1 +1 +1024 +1048576 +1073741824 +1 +14 +14680064 +0 diff --git a/tests/basic/ini_parse_quantity_warnings.phpt b/tests/basic/ini_parse_quantity_warnings.phpt new file mode 100644 index 0000000000000..f18753c853151 --- /dev/null +++ b/tests/basic/ini_parse_quantity_warnings.phpt @@ -0,0 +1,14 @@ +--TEST-- +ini_parse_quantity() function - warns when given inappropriate values +--INI-- +error_reporting = E_ALL +--FILE-- + +--EXPECTF-- +Warning: Invalid quantity "1mb": unknown multipler "b", interpreting as "1" for backwards compatibility in %sini_parse_quantity_warnings.php on line 3 + +Warning: Invalid quantity "256 then skip a few then g", interpreting as "256 g" for backwards compatibility in %sini_parse_quantity_warnings.php on line 4