diff --git a/Zend/tests/018.phpt b/Zend/tests/018.phpt index 97e53b105008f..f0610e47c7e47 100644 --- a/Zend/tests/018.phpt +++ b/Zend/tests/018.phpt @@ -3,10 +3,19 @@ constant() tests --FILE-- getMessage() . "\n"; +} + +try { + constant('::'); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} define("TEST_CONST2", "test"); var_dump(constant("TEST_CONST2")); @@ -14,8 +23,7 @@ var_dump(constant("TEST_CONST2")); echo "Done\n"; ?> --EXPECTF-- -Warning: constant(): Couldn't find constant in %s on line %d -NULL -int(1) +Couldn't find constant +Couldn't find constant :: string(4) "test" Done diff --git a/Zend/tests/bug41026.phpt b/Zend/tests/bug41026.phpt index e159ad36f6db4..0843d37d13df4 100644 --- a/Zend/tests/bug41026.phpt +++ b/Zend/tests/bug41026.phpt @@ -7,7 +7,7 @@ class try_class { static public function main () { - register_shutdown_function (array ("self", "on_shutdown")); + register_shutdown_function(array ("self", "on_shutdown")); } static public function on_shutdown () @@ -16,11 +16,13 @@ class try_class } } -try_class::main (); - +try_class::main(); echo "Done\n"; ?> --EXPECT-- Done -Warning: (Registered shutdown functions) Unable to call self::on_shutdown() - function does not exist in Unknown on line 0 +Fatal error: Uncaught ValueError: (Registered shutdown functions) Unable to call self::on_shutdown() - function does not exist in [no active file]:0 +Stack trace: +#0 {main} + thrown in [no active file] on line 0 diff --git a/Zend/tests/bug51791.phpt b/Zend/tests/bug51791.phpt index 0b92fa8c62592..817321e6b7afa 100644 --- a/Zend/tests/bug51791.phpt +++ b/Zend/tests/bug51791.phpt @@ -6,9 +6,12 @@ Bug #51791 (constant() failed to check undefined constant and php interpreter st class A { const B = 1; } -var_dump(constant('A::B1')); +try { + constant('A::B1'); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} ?> ---EXPECTF-- -Warning: constant(): Couldn't find constant A::B1 in %s on line %d -NULL +--EXPECT-- +Couldn't find constant A::B1 diff --git a/ext/iconv/tests/iconv_strpos.phpt b/ext/iconv/tests/iconv_strpos.phpt index 92492c7244af3..9a1e5a77b6d37 100644 --- a/ext/iconv/tests/iconv_strpos.phpt +++ b/ext/iconv/tests/iconv_strpos.phpt @@ -6,17 +6,16 @@ iconv_strpos() iconv.internal_charset=ISO-8859-1 --FILE-- getMessage() . "\n"; + } if ($to_charset !== false) { var_dump(iconv_strpos($haystk, $needle, $offset, $to_charset)); } else { @@ -42,8 +41,7 @@ bool(false) bool(false) int(5) int(5) -2: %s -bool(false) +Offset not contained in string bool(false) int(7) int(7) diff --git a/ext/mbstring/tests/bug43841.phpt b/ext/mbstring/tests/bug43841.phpt index ab52eb51c94ac..5585ba3963046 100644 --- a/ext/mbstring/tests/bug43841.phpt +++ b/ext/mbstring/tests/bug43841.phpt @@ -30,7 +30,11 @@ foreach ($offsets as $i) { echo "mb_strrpos:\n"; var_dump(mb_strrpos('This is na English ta', 'a', $i)); echo "strrpos:\n"; - var_dump(strrpos('This is na English ta', 'a', $i)); + try { + var_dump(strrpos('This is na English ta', 'a', $i)); + } catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; + } } ?> --EXPECTF-- @@ -45,9 +49,7 @@ mb_strrpos: Warning: mb_strrpos(): Offset is greater than the length of haystack string in %s on line %d bool(false) strrpos: - -Warning: strrpos(): Offset not contained in string in %s on line %d -bool(false) +Offset not contained in string -- Offset is -24 -- Multibyte String: @@ -60,9 +62,7 @@ mb_strrpos: Warning: mb_strrpos(): Offset is greater than the length of haystack string in %s on line %d bool(false) strrpos: - -Warning: strrpos(): Offset not contained in string in %s on line %d -bool(false) +Offset not contained in string -- Offset is -13 -- Multibyte String: diff --git a/ext/mbstring/tests/bug45923.phpt b/ext/mbstring/tests/bug45923.phpt index 6fc8e1db0989c..268917bbd87d0 100644 --- a/ext/mbstring/tests/bug45923.phpt +++ b/ext/mbstring/tests/bug45923.phpt @@ -10,7 +10,11 @@ function section($func, $haystack, $needle) echo "\n------- $func -----------\n\n"; foreach(array(0, 3, 6, 9, 11, 12, -1, -3, -6, -20) as $offset) { echo "> Offset: $offset\n"; - var_dump($func($haystack,$needle,$offset)); + try { + var_dump($func($haystack,$needle,$offset)); + } catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; + } } } @@ -40,9 +44,7 @@ bool(false) > Offset: 11 bool(false) > Offset: 12 - -Warning: strpos(): Offset not contained in string in %s on line %d -bool(false) +Offset not contained in string > Offset: -1 bool(false) > Offset: -3 @@ -50,9 +52,7 @@ int(8) > Offset: -6 int(8) > Offset: -20 - -Warning: strpos(): Offset not contained in string in %s on line %d -bool(false) +Offset not contained in string ------- mb_strpos ----------- @@ -94,9 +94,7 @@ bool(false) > Offset: 11 bool(false) > Offset: 12 - -Warning: stripos(): Offset not contained in string in %s on line %d -bool(false) +Offset not contained in string > Offset: -1 bool(false) > Offset: -3 @@ -104,9 +102,7 @@ int(8) > Offset: -6 int(8) > Offset: -20 - -Warning: stripos(): Offset not contained in string in %s on line %d -bool(false) +Offset not contained in string ------- mb_stripos ----------- @@ -148,9 +144,7 @@ bool(false) > Offset: 11 bool(false) > Offset: 12 - -Warning: strrpos(): Offset not contained in string in %s on line %d -bool(false) +Offset not contained in string > Offset: -1 int(8) > Offset: -3 @@ -158,9 +152,7 @@ int(8) > Offset: -6 int(4) > Offset: -20 - -Warning: strrpos(): Offset not contained in string in %s on line %d -bool(false) +Offset not contained in string ------- mb_strrpos ----------- @@ -202,9 +194,7 @@ bool(false) > Offset: 11 bool(false) > Offset: 12 - -Warning: strripos(): Offset not contained in string in %s on line %d -bool(false) +Offset not contained in string > Offset: -1 int(8) > Offset: -3 @@ -212,9 +202,7 @@ int(8) > Offset: -6 int(4) > Offset: -20 - -Warning: strripos(): Offset not contained in string in %s on line %d -bool(false) +Offset not contained in string ------- mb_strripos ----------- diff --git a/ext/opcache/Optimizer/zend_func_info.c b/ext/opcache/Optimizer/zend_func_info.c index 0f4bcb2570332..33c5025f1d635 100644 --- a/ext/opcache/Optimizer/zend_func_info.c +++ b/ext/opcache/Optimizer/zend_func_info.c @@ -295,7 +295,7 @@ static const func_info_t func_infos[] = { F1("highlight_string", MAY_BE_FALSE | MAY_BE_TRUE | MAY_BE_STRING), F1("php_strip_whitespace", MAY_BE_STRING), FN("ini_get", MAY_BE_FALSE | MAY_BE_STRING), - F1("ini_get_all", MAY_BE_FALSE | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_STRING | MAY_BE_ARRAY_OF_NULL | MAY_BE_ARRAY_OF_STRING | MAY_BE_ARRAY_OF_ARRAY), + F1("ini_get_all", MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_STRING | MAY_BE_ARRAY_OF_NULL | MAY_BE_ARRAY_OF_STRING | MAY_BE_ARRAY_OF_ARRAY), FN("ini_set", MAY_BE_FALSE | MAY_BE_STRING), F1("ini_alter", MAY_BE_FALSE | MAY_BE_STRING), F1("get_include_path", MAY_BE_FALSE | MAY_BE_STRING), diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 4969b73f84deb..ed2c9648f91d5 100755 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -1700,7 +1700,7 @@ PHP_FUNCTION(constant) } } else { if (!EG(exception)) { - php_error_docref(NULL, E_WARNING, "Couldn't find constant %s", ZSTR_VAL(const_name)); + zend_value_error("Couldn't find constant %s", ZSTR_VAL(const_name)); } RETURN_NULL(); } @@ -2840,7 +2840,7 @@ static int user_shutdown_function_call(zval *zv) /* {{{ */ if (!zend_is_callable(&shutdown_function_entry->arguments[0], 0, NULL)) { zend_string *function_name = zend_get_callable_name(&shutdown_function_entry->arguments[0]); - php_error(E_WARNING, "(Registered shutdown functions) Unable to call %s() - function does not exist", ZSTR_VAL(function_name)); + zend_value_error("(Registered shutdown functions) Unable to call %s() - function does not exist", ZSTR_VAL(function_name)); zend_string_release_ex(function_name, 0); return 0; } @@ -2878,15 +2878,15 @@ static void user_tick_function_call(user_tick_function_entry *tick_fe) /* {{{ */ zval *obj, *method; if (Z_TYPE_P(function) == IS_STRING) { - php_error_docref(NULL, E_WARNING, "Unable to call %s() - function does not exist", Z_STRVAL_P(function)); + zend_value_error("Unable to call %s() - function does not exist", Z_STRVAL_P(function)); } else if ( Z_TYPE_P(function) == IS_ARRAY && (obj = zend_hash_index_find(Z_ARRVAL_P(function), 0)) != NULL && (method = zend_hash_index_find(Z_ARRVAL_P(function), 1)) != NULL && Z_TYPE_P(obj) == IS_OBJECT && Z_TYPE_P(method) == IS_STRING) { - php_error_docref(NULL, E_WARNING, "Unable to call %s::%s() - function does not exist", ZSTR_VAL(Z_OBJCE_P(obj)->name), Z_STRVAL_P(method)); + zend_value_error("Unable to call %s::%s() - function does not exist", ZSTR_VAL(Z_OBJCE_P(obj)->name), Z_STRVAL_P(method)); } else { - php_error_docref(NULL, E_WARNING, "Unable to call tick function"); + zend_value_error("Unable to call tick function"); } } @@ -3194,7 +3194,7 @@ PHP_FUNCTION(ini_get) } /* }}} */ -/* {{{ proto array|false ini_get_all([string extension[, bool details = true]]) +/* {{{ proto array ini_get_all([string extension[, bool details = true]]) Get all configuration options */ PHP_FUNCTION(ini_get_all) { @@ -3205,7 +3205,6 @@ PHP_FUNCTION(ini_get_all) zend_string *key; zend_ini_entry *ini_entry; - ZEND_PARSE_PARAMETERS_START(0, 2) Z_PARAM_OPTIONAL Z_PARAM_STRING_OR_NULL(extname, extname_len) @@ -3216,8 +3215,8 @@ PHP_FUNCTION(ini_get_all) if (extname) { if ((module = zend_hash_str_find_ptr(&module_registry, extname, extname_len)) == NULL) { - php_error_docref(NULL, E_WARNING, "Unable to find extension '%s'", extname); - RETURN_FALSE; + zend_value_error("Unable to find extension '%s'", extname); + return; } module_number = module->module_number; } @@ -3853,8 +3852,8 @@ PHP_FUNCTION(parse_ini_file) ZEND_PARSE_PARAMETERS_END(); if (filename_len == 0) { - php_error_docref(NULL, E_WARNING, "Filename cannot be empty!"); - RETURN_FALSE; + zend_value_error("Filename cannot be empty!"); + return; } /* Set callback function */ diff --git a/ext/standard/basic_functions.stub.php b/ext/standard/basic_functions.stub.php index 630f8c29d7750..0e2326fe70696 100755 --- a/ext/standard/basic_functions.stub.php +++ b/ext/standard/basic_functions.stub.php @@ -311,7 +311,7 @@ function highlight_string(string $string, bool $return = false): string|bool|nul function ini_get(string $varname): string|false {} -function ini_get_all(?string $extension = null, bool $details = true): array|false {} +function ini_get_all(?string $extension = null, bool $details = true): array {} function ini_set(string $varname, string $value): string|false {} diff --git a/ext/standard/basic_functions_arginfo.h b/ext/standard/basic_functions_arginfo.h index 43dee46b7ab60..77f000a10b4f5 100755 --- a/ext/standard/basic_functions_arginfo.h +++ b/ext/standard/basic_functions_arginfo.h @@ -476,7 +476,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_ini_get, 0, 1, MAY_BE_STRING|MAY ZEND_ARG_TYPE_INFO(0, varname, IS_STRING, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_ini_get_all, 0, 0, MAY_BE_ARRAY|MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ini_get_all, 0, 0, IS_ARRAY, 0) ZEND_ARG_TYPE_INFO(0, extension, IS_STRING, 1) ZEND_ARG_TYPE_INFO(0, details, _IS_BOOL, 0) ZEND_END_ARG_INFO() diff --git a/ext/standard/browscap.c b/ext/standard/browscap.c index 8e99b925dbafd..980719fa0b3e7 100644 --- a/ext/standard/browscap.c +++ b/ext/standard/browscap.c @@ -701,8 +701,8 @@ PHP_FUNCTION(get_browser) } } else { if (!global_bdata.htab) { - php_error_docref(NULL, E_WARNING, "browscap ini directive not set"); - RETURN_FALSE; + zend_throw_error(NULL, "Browscap ini directive not set"); + return; } bdata = &global_bdata; } diff --git a/ext/standard/dl.c b/ext/standard/dl.c index 1edfb944fc403..efe6ea8182c8b 100644 --- a/ext/standard/dl.c +++ b/ext/standard/dl.c @@ -50,13 +50,13 @@ PHPAPI PHP_FUNCTION(dl) ZEND_PARSE_PARAMETERS_END(); if (!PG(enable_dl)) { - php_error_docref(NULL, E_WARNING, "Dynamically loaded extensions aren't enabled"); - RETURN_FALSE; + zend_throw_error(NULL, "Dynamically loaded extensions aren't enabled"); + return; } if (filename_len >= MAXPATHLEN) { - php_error_docref(NULL, E_WARNING, "File name exceeds the maximum allowed length of %d characters", MAXPATHLEN); - RETURN_FALSE; + zend_value_error("File name exceeds the maximum allowed length of %d characters", MAXPATHLEN); + return; } php_dl(filename, MODULE_TEMPORARY, return_value, 0); @@ -265,7 +265,7 @@ PHP_MINFO_FUNCTION(dl) PHPAPI void php_dl(char *file, int type, zval *return_value, int start_now) { - php_error_docref(NULL, E_WARNING, "Cannot dynamically load %s - dynamic modules are not supported", file); + zend_throw_error(NULL, "Cannot dynamically load %s - dynamic modules are not supported", file); RETVAL_FALSE; } diff --git a/ext/standard/dns.c b/ext/standard/dns.c index c3a9b9cde66ab..d46226aafd1d3 100644 --- a/ext/standard/dns.c +++ b/ext/standard/dns.c @@ -383,8 +383,8 @@ PHP_FUNCTION(dns_check_record) ZEND_PARSE_PARAMETERS_END(); if (hostname_len == 0) { - php_error_docref(NULL, E_WARNING, "Host cannot be empty"); - RETURN_FALSE; + zend_value_error("Host cannot be empty"); + return; } if (rectype) { diff --git a/ext/standard/dns_win32.c b/ext/standard/dns_win32.c index 5dc39a104ba0a..1221cbb6fb77b 100644 --- a/ext/standard/dns_win32.c +++ b/ext/standard/dns_win32.c @@ -107,8 +107,8 @@ PHP_FUNCTION(dns_check_record) } if (hostname_len == 0) { - php_error_docref(NULL, E_WARNING, "Host cannot be empty"); - RETURN_FALSE; + zend_value_error("Host cannot be empty"); + return; } if (rectype) { diff --git a/ext/standard/filestat.c b/ext/standard/filestat.c index f2514d16d2887..8dbfcaace4332 100644 --- a/ext/standard/filestat.c +++ b/ext/standard/filestat.c @@ -354,7 +354,7 @@ static void php_do_chgrp(INTERNAL_FUNCTION_PARAMETERS, int do_lchgrp) /* {{{ */ option = PHP_STREAM_META_GROUP_NAME; value = Z_STRVAL_P(group); } else { - php_error_docref(NULL, E_WARNING, "parameter 2 should be string or int, %s given", zend_zval_type_name(group)); + zend_type_error("Parameter 2 should be string or int, %s given", zend_zval_type_name(group)); RETURN_FALSE; } if(wrapper->wops->stream_metadata(wrapper, filename, option, value, NULL)) { @@ -383,7 +383,7 @@ static void php_do_chgrp(INTERNAL_FUNCTION_PARAMETERS, int do_lchgrp) /* {{{ */ RETURN_FALSE; } } else { - php_error_docref(NULL, E_WARNING, "parameter 2 should be string or int, %s given", zend_zval_type_name(group)); + zend_type_error("Parameter 2 should be string or int, %s given", zend_zval_type_name(group)); RETURN_FALSE; } diff --git a/ext/standard/ftp_fopen_wrapper.c b/ext/standard/ftp_fopen_wrapper.c index 2c01e88f4f3a6..8c58caef08e9b 100644 --- a/ext/standard/ftp_fopen_wrapper.c +++ b/ext/standard/ftp_fopen_wrapper.c @@ -1050,7 +1050,7 @@ static int php_stream_ftp_mkdir(php_stream_wrapper *wrapper, const char *url, in if (resource->path == NULL) { if (options & REPORT_ERRORS) { - php_error_docref(NULL, E_WARNING, "Invalid path provided in %s", url); + zend_value_error("Invalid path provided in %s", url); } goto mkdir_errexit; } @@ -1143,7 +1143,7 @@ static int php_stream_ftp_rmdir(php_stream_wrapper *wrapper, const char *url, in if (resource->path == NULL) { if (options & REPORT_ERRORS) { - php_error_docref(NULL, E_WARNING, "Invalid path provided in %s", url); + zend_value_error("Invalid path provided in %s", url); } goto rmdir_errexit; } diff --git a/ext/standard/levenshtein.c b/ext/standard/levenshtein.c index 3147c2bbe6aa5..1d65086ffdb09 100644 --- a/ext/standard/levenshtein.c +++ b/ext/standard/levenshtein.c @@ -123,7 +123,7 @@ PHP_FUNCTION(levenshtein) } if (distance < 0 && /* TODO */ ZEND_NUM_ARGS() != 3) { - php_error_docref(NULL, E_WARNING, "Argument string(s) too long"); + zend_value_error("Argument string(s) too long"); } RETURN_LONG(distance); diff --git a/ext/standard/password.c b/ext/standard/password.c index 17896e77ee6fa..61a5b725bde78 100644 --- a/ext/standard/password.c +++ b/ext/standard/password.c @@ -83,7 +83,7 @@ static zend_string* php_password_make_salt(size_t length) /* {{{ */ zend_string *ret, *buffer; if (length > (INT_MAX / 3)) { - php_error_docref(NULL, E_WARNING, "Length is too large to safely generate"); + zend_value_error("Length is too large to safely generate"); return NULL; } @@ -193,7 +193,7 @@ static zend_string* php_password_bcrypt_hash(const zend_string *password, zend_a } if (cost < 4 || cost > 31) { - php_error_docref(NULL, E_WARNING, "Invalid bcrypt cost parameter specified: " ZEND_LONG_FMT, cost); + zend_value_error("Invalid bcrypt cost parameter specified: " ZEND_LONG_FMT, cost); return NULL; } @@ -316,7 +316,7 @@ static zend_string *php_password_argon2_hash(const zend_string *password, zend_a } if (memory_cost > ARGON2_MAX_MEMORY || memory_cost < ARGON2_MIN_MEMORY) { - php_error_docref(NULL, E_WARNING, "Memory cost is outside of allowed memory range"); + zend_value_error("Memory cost is outside of allowed memory range"); return NULL; } @@ -325,7 +325,7 @@ static zend_string *php_password_argon2_hash(const zend_string *password, zend_a } if (time_cost > ARGON2_MAX_TIME || time_cost < ARGON2_MIN_TIME) { - php_error_docref(NULL, E_WARNING, "Time cost is outside of allowed time range"); + zend_value_error("Time cost is outside of allowed time range"); return NULL; } @@ -334,7 +334,7 @@ static zend_string *php_password_argon2_hash(const zend_string *password, zend_a } if (threads > ARGON2_MAX_LANES || threads == 0) { - php_error_docref(NULL, E_WARNING, "Invalid number of threads"); + zend_value_error("Invalid number of threads"); return NULL; } @@ -669,9 +669,9 @@ PHP_FUNCTION(password_hash) algo = php_password_algo_find_zval(zalgo); if (!algo) { zend_string *algostr = zval_get_string(zalgo); - php_error_docref(NULL, E_WARNING, "Unknown password hashing algorithm: %s", ZSTR_VAL(algostr)); + zend_value_error("Unknown password hashing algorithm: %s", ZSTR_VAL(algostr)); zend_string_release(algostr); - RETURN_NULL(); + return; } digest = algo->hash(password, options); diff --git a/ext/standard/php_fopen_wrapper.c b/ext/standard/php_fopen_wrapper.c index f525f868e468f..7d8f4ed3e1f43 100644 --- a/ext/standard/php_fopen_wrapper.c +++ b/ext/standard/php_fopen_wrapper.c @@ -219,7 +219,7 @@ php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, const char *pa if ((options & STREAM_OPEN_FOR_INCLUDE) && !PG(allow_url_include) ) { if (options & REPORT_ERRORS) { - php_error_docref(NULL, E_WARNING, "URL file-access is disabled in the server configuration"); + zend_throw_error(NULL, "URL file-access is disabled in the server configuration"); } return NULL; } @@ -238,7 +238,7 @@ php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, const char *pa if (!strcasecmp(path, "stdin")) { if ((options & STREAM_OPEN_FOR_INCLUDE) && !PG(allow_url_include) ) { if (options & REPORT_ERRORS) { - php_error_docref(NULL, E_WARNING, "URL file-access is disabled in the server configuration"); + zend_throw_error(NULL, "URL file-access is disabled in the server configuration"); } return NULL; } @@ -297,14 +297,14 @@ php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, const char *pa if (strcmp(sapi_module.name, "cli")) { if (options & REPORT_ERRORS) { - php_error_docref(NULL, E_WARNING, "Direct access to file descriptors is only available from command-line PHP"); + zend_throw_error(NULL, "Direct access to file descriptors is only available from command-line PHP"); } return NULL; } if ((options & STREAM_OPEN_FOR_INCLUDE) && !PG(allow_url_include) ) { if (options & REPORT_ERRORS) { - php_error_docref(NULL, E_WARNING, "URL file-access is disabled in the server configuration"); + zend_throw_error(NULL, "URL file-access is disabled in the server configuration"); } return NULL; } diff --git a/ext/standard/proc_open.c b/ext/standard/proc_open.c index 4906b3f828375..85bd2c9f57c8e 100644 --- a/ext/standard/proc_open.c +++ b/ext/standard/proc_open.c @@ -529,8 +529,8 @@ PHP_FUNCTION(proc_open) zval *arg_zv; uint32_t num_elems = zend_hash_num_elements(Z_ARRVAL_P(command_zv)); if (num_elems == 0) { - php_error_docref(NULL, E_WARNING, "Command array must have at least one element"); - RETURN_FALSE; + zend_value_error("Command array must have at least one element"); + return; } #ifdef PHP_WIN32 @@ -622,7 +622,7 @@ PHP_FUNCTION(proc_open) zval *ztype; if (str_index) { - php_error_docref(NULL, E_WARNING, "descriptor spec must be an integer indexed array"); + zend_value_error("Descriptor spec must be an integer indexed array"); goto exit_fail; } @@ -655,7 +655,7 @@ PHP_FUNCTION(proc_open) descriptors[ndesc].mode = DESC_FILE; } else if (Z_TYPE_P(descitem) != IS_ARRAY) { - php_error_docref(NULL, E_WARNING, "Descriptor item must be either an array or a File-Handle"); + zend_value_error("Descriptor item must be either an array or a File-Handle"); goto exit_fail; } else { @@ -664,7 +664,7 @@ PHP_FUNCTION(proc_open) goto exit_fail; } } else { - php_error_docref(NULL, E_WARNING, "Missing handle qualifier in array"); + zend_value_error("Missing handle qualifier in array"); goto exit_fail; } @@ -677,7 +677,7 @@ PHP_FUNCTION(proc_open) goto exit_fail; } } else { - php_error_docref(NULL, E_WARNING, "Missing mode parameter for 'pipe'"); + zend_value_error("Missing mode parameter for 'pipe'"); goto exit_fail; } @@ -718,7 +718,7 @@ PHP_FUNCTION(proc_open) goto exit_fail; } } else { - php_error_docref(NULL, E_WARNING, "Missing file name parameter for 'file'"); + zend_value_error("Missing file name parameter for 'file'"); goto exit_fail; } @@ -727,7 +727,7 @@ PHP_FUNCTION(proc_open) goto exit_fail; } } else { - php_error_docref(NULL, E_WARNING, "Missing mode parameter for 'file'"); + zend_value_error("Missing mode parameter for 'file'"); goto exit_fail; } @@ -760,11 +760,11 @@ PHP_FUNCTION(proc_open) php_file_descriptor_t childend; if (!ztarget) { - php_error_docref(NULL, E_WARNING, "Missing redirection target"); + zend_value_error("Missing redirection target"); goto exit_fail; } if (Z_TYPE_P(ztarget) != IS_LONG) { - php_error_docref(NULL, E_WARNING, "Redirection target must be an integer"); + zend_value_error("Redirection target must be an integer"); goto exit_fail; } diff --git a/ext/standard/string.c b/ext/standard/string.c index 8209b56860ad4..df82247791056 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -1883,8 +1883,8 @@ PHP_FUNCTION(strpos) offset += (zend_long)ZSTR_LEN(haystack); } if (offset < 0 || (size_t)offset > ZSTR_LEN(haystack)) { - php_error_docref(NULL, E_WARNING, "Offset not contained in string"); - RETURN_FALSE; + zend_value_error("Offset not contained in string"); + return; } found = (char*)php_memnstr(ZSTR_VAL(haystack) + offset, @@ -1919,8 +1919,8 @@ PHP_FUNCTION(stripos) offset += (zend_long)ZSTR_LEN(haystack); } if (offset < 0 || (size_t)offset > ZSTR_LEN(haystack)) { - php_error_docref(NULL, E_WARNING, "Offset not contained in string"); - RETURN_FALSE; + zend_value_error("Offset not contained in string"); + return; } if (ZSTR_LEN(needle) > ZSTR_LEN(haystack)) { @@ -1961,15 +1961,15 @@ PHP_FUNCTION(strrpos) if (offset >= 0) { if ((size_t)offset > ZSTR_LEN(haystack)) { - php_error_docref(NULL, E_WARNING, "Offset not contained in string"); - RETURN_FALSE; + zend_value_error("Offset not contained in string"); + return; } p = ZSTR_VAL(haystack) + (size_t)offset; e = ZSTR_VAL(haystack) + ZSTR_LEN(haystack); } else { if (offset < -INT_MAX || (size_t)(-offset) > ZSTR_LEN(haystack)) { - php_error_docref(NULL, E_WARNING, "Offset not contained in string"); - RETURN_FALSE; + zend_value_error("Offset not contained in string"); + return; } p = ZSTR_VAL(haystack); @@ -2011,16 +2011,16 @@ PHP_FUNCTION(strripos) char lowered; if (offset >= 0) { if ((size_t)offset > ZSTR_LEN(haystack)) { - php_error_docref(NULL, E_WARNING, "Offset not contained in string"); - RETURN_FALSE; + zend_value_error("Offset not contained in string"); + return; } p = ZSTR_VAL(haystack) + (size_t)offset; e = ZSTR_VAL(haystack) + ZSTR_LEN(haystack) - 1; } else { p = ZSTR_VAL(haystack); if (offset < -INT_MAX || (size_t)(-offset) > ZSTR_LEN(haystack)) { - php_error_docref(NULL, E_WARNING, "Offset not contained in string"); - RETURN_FALSE; + zend_value_error("Offset not contained in string"); + return; } e = ZSTR_VAL(haystack) + (ZSTR_LEN(haystack) + (size_t)offset); } @@ -2039,16 +2039,16 @@ PHP_FUNCTION(strripos) if (offset >= 0) { if ((size_t)offset > ZSTR_LEN(haystack)) { zend_string_release_ex(haystack_dup, 0); - php_error_docref(NULL, E_WARNING, "Offset not contained in string"); - RETURN_FALSE; + zend_value_error("Offset not contained in string"); + return; } p = ZSTR_VAL(haystack_dup) + offset; e = ZSTR_VAL(haystack_dup) + ZSTR_LEN(haystack); } else { if (offset < -INT_MAX || (size_t)(-offset) > ZSTR_LEN(haystack)) { zend_string_release_ex(haystack_dup, 0); - php_error_docref(NULL, E_WARNING, "Offset not contained in string"); - RETURN_FALSE; + zend_value_error("Offset not contained in string"); + return; } p = ZSTR_VAL(haystack_dup); @@ -5545,8 +5545,8 @@ PHP_FUNCTION(substr_count) offset += (zend_long)haystack_len; } if ((offset < 0) || ((size_t)offset > haystack_len)) { - php_error_docref(NULL, E_WARNING, "Offset not contained in string"); - RETURN_FALSE; + zend_value_error("Offset not contained in string"); + return; } p += offset; diff --git a/ext/standard/tests/file/chgrp.phpt b/ext/standard/tests/file/chgrp.phpt index 03ea24141bb0a..9003979a7526e 100644 --- a/ext/standard/tests/file/chgrp.phpt +++ b/ext/standard/tests/file/chgrp.phpt @@ -7,9 +7,11 @@ if(substr(PHP_OS, 0, 3) == "WIN") ?> --FILE-- getMessage() . "\n"; +} ?> --EXPECTF-- -Warning: chgrp(): parameter 2 should be string or int, null given in %schgrp.php on line 2 -ALIVE +Parameter 2 should be string or int, null given diff --git a/ext/standard/tests/general_functions/bug72920.phpt b/ext/standard/tests/general_functions/bug72920.phpt index 8ba4d26713626..ab0159596eabf 100644 --- a/ext/standard/tests/general_functions/bug72920.phpt +++ b/ext/standard/tests/general_functions/bug72920.phpt @@ -6,7 +6,10 @@ class Foo { private const C1 = "a"; } -var_dump(constant('Foo::C1')); ---EXPECTF-- -Warning: constant(): Couldn't find constant Foo::C1 in %s on line %d -NULL +try { + constant('Foo::C1'); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} +--EXPECT-- +Couldn't find constant Foo::C1 diff --git a/ext/standard/tests/general_functions/dl-check-enabled.phpt b/ext/standard/tests/general_functions/dl-check-enabled.phpt index 7559b8d905c90..57cf49078d99a 100644 --- a/ext/standard/tests/general_functions/dl-check-enabled.phpt +++ b/ext/standard/tests/general_functions/dl-check-enabled.phpt @@ -1,6 +1,6 @@ --TEST-- dl() returns false when disabled via INI settings -+--CREDITS-- +--CREDITS-- Tom Van Herreweghe User Group: PHP-WVL & PHPGent #PHPTestFest --SKIPIF-- @@ -14,9 +14,11 @@ if (!in_array(php_sapi_name(), $enabled_sapi)) { enable_dl=0 --FILE-- getMessage() . "\n"; +} ?> ---EXPECTF-- - -Warning: dl(): Dynamically loaded extensions aren't enabled in %s on line %d -bool(false) +--EXPECT-- +Dynamically loaded extensions aren't enabled diff --git a/ext/standard/tests/general_functions/dl-cve-2007-4887.phpt b/ext/standard/tests/general_functions/dl-cve-2007-4887.phpt index 263c9a6def492..08cc33aa16ea8 100644 --- a/ext/standard/tests/general_functions/dl-cve-2007-4887.phpt +++ b/ext/standard/tests/general_functions/dl-cve-2007-4887.phpt @@ -11,8 +11,11 @@ if (!in_array(php_sapi_name(), $enabled_sapi)) { enable_dl=1 --FILE-- getMessage() . "\n"; +} ?> --EXPECTF-- -Warning: dl(): File name exceeds the maximum allowed length of %d characters in %s on line %d -bool(false) +File name exceeds the maximum allowed length of %d characters diff --git a/ext/standard/tests/general_functions/ini_get_all.phpt b/ext/standard/tests/general_functions/ini_get_all.phpt index ca450f1bc43ba..ea7226fa0b655 100644 --- a/ext/standard/tests/general_functions/ini_get_all.phpt +++ b/ext/standard/tests/general_functions/ini_get_all.phpt @@ -10,25 +10,32 @@ pcre.recursion_limit=100000 getMessage() . "\n"; +} +try { + var_dump(ini_get_all("nosuchextension")); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} var_dump(ini_get_all("reflection")); var_dump(ini_get_all("pcre")); var_dump(ini_get_all("pcre", false)); var_dump(ini_get_all("reflection", false)); - -var_dump(ini_get_all("", "")); +try { + ini_get_all("", ""); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} echo "Done\n"; ?> ---EXPECTF-- +--EXPECT-- string(5) "array" - -Warning: ini_get_all(): Unable to find extension '' in %s on line %d -bool(false) - -Warning: ini_get_all(): Unable to find extension 'nosuchextension' in %s on line %d -bool(false) +Unable to find extension '' +Unable to find extension 'nosuchextension' array(0) { } array(3) { @@ -70,7 +77,5 @@ array(3) { } array(0) { } - -Warning: ini_get_all(): Unable to find extension '' in %sini_get_all.php on line %d -bool(false) +Unable to find extension '' Done diff --git a/ext/standard/tests/general_functions/proc_open_array.phpt b/ext/standard/tests/general_functions/proc_open_array.phpt index 8b42a55bacaf6..99e1cc56cb4d3 100644 --- a/ext/standard/tests/general_functions/proc_open_array.phpt +++ b/ext/standard/tests/general_functions/proc_open_array.phpt @@ -10,8 +10,12 @@ $ds = [ 2 => ['pipe', 'w'], ]; -echo "Empty command array:"; -var_dump(proc_open([], $ds, $pipes)); +echo "Empty command array:\n"; +try { + proc_open([], $ds, $pipes); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} echo "\nNul byte in program name:"; var_dump(proc_open(["php\0oops"], $ds, $pipes)); @@ -56,8 +60,7 @@ proc_close($proc); ?> --EXPECTF-- Empty command array: -Warning: proc_open(): Command array must have at least one element in %s on line %d -bool(false) +Command array must have at least one element Nul byte in program name: Warning: proc_open(): Command array element 1 contains a null byte in %s on line %d diff --git a/ext/standard/tests/general_functions/proc_open_pipes3.phpt b/ext/standard/tests/general_functions/proc_open_pipes3.phpt index 7671b1dce1794..b83a0e1a07381 100644 --- a/ext/standard/tests/general_functions/proc_open_pipes3.phpt +++ b/ext/standard/tests/general_functions/proc_open_pipes3.phpt @@ -14,7 +14,11 @@ $spec[$i] = array('pi'); proc_open("$php -n $callee", $spec, $pipes); $spec[$i] = 1; -proc_open("$php -n $callee", $spec, $pipes); +try { + proc_open("$php -n $callee", $spec, $pipes); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} $spec[$i] = array('pipe', "test"); proc_open("$php -n $callee", $spec, $pipes); @@ -28,8 +32,7 @@ echo "END\n"; ?> --EXPECTF-- Warning: proc_open(): pi is not a valid descriptor spec/mode in %s on line %d - -Warning: proc_open(): Descriptor item must be either an array or a File-Handle in %s on line %d +Descriptor item must be either an array or a File-Handle array(4) { [3]=> resource(%d) of type (Unknown) diff --git a/ext/standard/tests/general_functions/proc_open_redirect.phpt b/ext/standard/tests/general_functions/proc_open_redirect.phpt index 92da696ee9d98..bf0412c0a2f58 100644 --- a/ext/standard/tests/general_functions/proc_open_redirect.phpt +++ b/ext/standard/tests/general_functions/proc_open_redirect.phpt @@ -4,9 +4,23 @@ Redirection support in proc_open getMessage() . "\n"; +} + +try { + proc_open([$php], [['redirect', 'foo']], $pipes); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} + +try { + proc_open([$php], [['redirect', 42]], $pipes); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} echo "\nWith pipe:\n"; $cmd = [$php, '-r', 'echo "Test\n"; fprintf(STDERR, "Error");']; @@ -38,14 +52,10 @@ proc_close($proc); ?> --EXPECTF-- -Warning: proc_open(): Missing redirection target in %s on line %d -bool(false) - -Warning: proc_open(): Redirection target must be an integer in %s on line %d -bool(false) +Missing redirection target +Redirection target must be an integer -Warning: proc_open(): Redirection target 42 not found in %s on line %d -bool(false) +Warning: proc_open(): Redirection target 42 not found in %s With pipe: array(1) { diff --git a/ext/standard/tests/network/bug41347.phpt b/ext/standard/tests/network/bug41347.phpt index 6ece098191de5..6390327a52bef 100644 --- a/ext/standard/tests/network/bug41347.phpt +++ b/ext/standard/tests/network/bug41347.phpt @@ -2,8 +2,11 @@ dns_check_record() segfault with empty host --FILE-- getMessage() . "\n"; +} ?> ---EXPECTF-- -Warning: dns_check_record(): Host cannot be empty in %s on line %d -bool(false) +--EXPECT-- +Host cannot be empty diff --git a/ext/standard/tests/password/password_bcrypt_errors.phpt b/ext/standard/tests/password/password_bcrypt_errors.phpt index 64496744cb1a9..10c3483f5a80d 100644 --- a/ext/standard/tests/password/password_bcrypt_errors.phpt +++ b/ext/standard/tests/password/password_bcrypt_errors.phpt @@ -3,15 +3,18 @@ Test error operation of password_hash() with bcrypt hashing --FILE-- 3)); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} -var_dump(password_hash("foo", PASSWORD_BCRYPT, array("cost" => 3))); - -var_dump(password_hash("foo", PASSWORD_BCRYPT, array("cost" => 32))); - +try { + var_dump(password_hash("foo", PASSWORD_BCRYPT, array("cost" => 32))); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} ?> ---EXPECTF-- -Warning: password_hash(): Invalid bcrypt cost parameter specified: 3 in %s on line %d -NULL - -Warning: password_hash(): Invalid bcrypt cost parameter specified: 32 in %s on line %d -NULL +--EXPECT-- +Invalid bcrypt cost parameter specified: 3 +Invalid bcrypt cost parameter specified: 32 diff --git a/ext/standard/tests/password/password_hash_error.phpt b/ext/standard/tests/password/password_hash_error.phpt index cb50654905907..a0d8c6461e71f 100644 --- a/ext/standard/tests/password/password_hash_error.phpt +++ b/ext/standard/tests/password/password_hash_error.phpt @@ -10,7 +10,11 @@ try { echo $e->getMessage(), "\n"; } -var_dump(password_hash("foo", array())); +try { + password_hash("foo", array()); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} try { var_dump(password_hash("foo", 19, new StdClass)); @@ -35,9 +39,7 @@ try { password_hash() expects at least 2 parameters, 1 given Warning: Array to string conversion in %s on line %d - -Warning: password_hash(): Unknown password hashing algorithm: Array in %s on line %d -NULL +Unknown password hashing algorithm: Array password_hash() expects parameter 3 to be array, object given password_hash() expects parameter 3 to be array, string given password_hash() expects parameter 1 to be string, array given diff --git a/ext/standard/tests/password/password_hash_error_argon2.phpt b/ext/standard/tests/password/password_hash_error_argon2.phpt index 2ea6b93627c0f..0fdb0c2ba83e4 100644 --- a/ext/standard/tests/password/password_hash_error_argon2.phpt +++ b/ext/standard/tests/password/password_hash_error_argon2.phpt @@ -7,28 +7,46 @@ if (!defined('PASSWORD_ARGON2ID')) die('skip password_hash not built with Argon2 ?> --FILE-- 0])); -var_dump(password_hash('test', PASSWORD_ARGON2I, ['time_cost' => 0])); -var_dump(password_hash('test', PASSWORD_ARGON2I, ['threads' => 0])); -var_dump(password_hash('test', PASSWORD_ARGON2ID, ['memory_cost' => 0])); -var_dump(password_hash('test', PASSWORD_ARGON2ID, ['time_cost' => 0])); -var_dump(password_hash('test', PASSWORD_ARGON2ID, ['threads' => 0])); -?> ---EXPECTF-- -Warning: password_hash(): Memory cost is outside of allowed memory range in %s on line %d -NULL +try { + var_dump(password_hash('test', PASSWORD_ARGON2I, ['memory_cost' => 0])); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} -Warning: password_hash(): Time cost is outside of allowed time range in %s on line %d -NULL +try { + var_dump(password_hash('test', PASSWORD_ARGON2I, ['time_cost' => 0])); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} -Warning: password_hash(): %sthread%s -NULL +try { + var_dump(password_hash('test', PASSWORD_ARGON2I, ['threads' => 0])); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} -Warning: password_hash(): Memory cost is outside of allowed memory range in %s on line %d -NULL +try { + var_dump(password_hash('test', PASSWORD_ARGON2ID, ['memory_cost' => 0])); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} -Warning: password_hash(): Time cost is outside of allowed time range in %s on line %d -NULL +try { + var_dump(password_hash('test', PASSWORD_ARGON2ID, ['time_cost' => 0])); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} -Warning: password_hash(): %sthread%s -NULL +try { + var_dump(password_hash('test', PASSWORD_ARGON2ID, ['threads' => 0])); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} +?> +--EXPECT-- +Memory cost is outside of allowed memory range +Time cost is outside of allowed time range +Invalid number of threads +Memory cost is outside of allowed memory range +Time cost is outside of allowed time range +Invalid number of threads diff --git a/ext/standard/tests/strings/bug40754.phpt b/ext/standard/tests/strings/bug40754.phpt index d502bff829e27..9e409bf271175 100644 --- a/ext/standard/tests/strings/bug40754.phpt +++ b/ext/standard/tests/strings/bug40754.phpt @@ -11,16 +11,52 @@ var_dump(substr_replace("abcde", "x", $v, $v)); var_dump(strspn("abcde", "abc", $v, $v)); var_dump(strcspn("abcde", "abc", $v, $v)); -var_dump(substr_count("abcde", "abc", $v, $v)); +try { + var_dump(substr_count("abcde", "abc", $v, $v)); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} + var_dump(substr_compare("abcde", "abc", $v, $v)); -var_dump(stripos("abcde", "abc", $v)); -var_dump(substr_count("abcde", "abc", $v, 1)); +try { + stripos("abcde", "abc", $v); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} + +try { + substr_count("abcde", "abc", $v, 1); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} + var_dump(substr_count("abcde", "abc", 1, $v)); -var_dump(strpos("abcde", "abc", $v)); -var_dump(stripos("abcde", "abc", $v)); -var_dump(strrpos("abcde", "abc", $v)); -var_dump(strripos("abcde", "abc", $v)); + +try { + strpos("abcde", "abc", $v); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} + +try { + stripos("abcde", "abc", $v); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} + +try { + strrpos("abcde", "abc", $v); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} + +try { + strripos("abcde", "abc", $v); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} + var_dump(strncmp("abcde", "abc", $v)); var_dump(chunk_split("abcde", $v, "abc")); var_dump(substr("abcde", $v, $v)); @@ -31,33 +67,19 @@ string(4) "bcde" string(6) "abcdex" bool(false) bool(false) - -Warning: substr_count(): Offset not contained in string in %s on line %d -bool(false) +Offset not contained in string Warning: substr_compare(): The start position cannot exceed initial string length in %s on line %d bool(false) - -Warning: stripos(): Offset not contained in string in %s on line %d -bool(false) - -Warning: substr_count(): Offset not contained in string in %s on line %d -bool(false) +Offset not contained in string +Offset not contained in string Warning: substr_count(): Invalid length value in %s on line %d bool(false) - -Warning: strpos(): Offset not contained in string in %s on line %d -bool(false) - -Warning: stripos(): Offset not contained in string in %s on line %d -bool(false) - -Warning: strrpos(): Offset not contained in string in %s on line %d -bool(false) - -Warning: strripos(): Offset not contained in string in %s on line %d -bool(false) +Offset not contained in string +Offset not contained in string +Offset not contained in string +Offset not contained in string int(2) string(8) "abcdeabc" bool(false) diff --git a/ext/standard/tests/strings/bug67252.phpt b/ext/standard/tests/strings/bug67252.phpt index eab2112afa359..8f0bba51fba8d 100644 --- a/ext/standard/tests/strings/bug67252.phpt +++ b/ext/standard/tests/strings/bug67252.phpt @@ -2,11 +2,11 @@ Bug #67252 (convert_uudecode out-of-bounds read) --FILE-- getMessage() . "\n"; +} ?> ---EXPECTF-- -Warning: convert_uudecode(): The given parameter is not a valid uuencoded string in %s on line %d -bool(false) +--EXPECT-- +The given parameter is not a valid uuencoded string diff --git a/ext/standard/tests/strings/levenshtein.phpt b/ext/standard/tests/strings/levenshtein.phpt index b4b7c03e7f580..f6daf694fbc05 100644 --- a/ext/standard/tests/strings/levenshtein.phpt +++ b/ext/standard/tests/strings/levenshtein.phpt @@ -56,23 +56,30 @@ $n += test_me("bug #16473", 2, "ax", "bcx"); $n += test_me("custom", -1, "111", "121", "my_levcode"); $n += test_me("lt maxlength1", 254, "AbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsu", "A"); -$n += test_me("gt maxlength1", -1, "AbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuv", "A"); - $n += test_me("lt maxlength2", 254, "A", "AbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsu"); -$n += test_me("gt maxlength2", -1, "A", "AbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuv"); echo ($n==0)?"all passed\n":"$n failed\n"; +try { + levenshtein("AbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuv", "A"); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} + +try { + levenshtein("A", "AbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuv"); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} + var_dump(levenshtein("", "", -1, -1, -1)); var_dump(levenshtein("", "", 10, 10, 10)); ?> --EXPECTF-- Warning: levenshtein(): The general Levenshtein support is not there yet in %s on line %d - -Warning: levenshtein(): Argument string(s) too long in %s on line %d - -Warning: levenshtein(): Argument string(s) too long in %s on line %d all passed +Argument string(s) too long +Argument string(s) too long int(0) int(0) diff --git a/ext/standard/tests/strings/stripos_error.phpt b/ext/standard/tests/strings/stripos_error.phpt index 0420bb090b268..caa93298748ab 100644 --- a/ext/standard/tests/strings/stripos_error.phpt +++ b/ext/standard/tests/strings/stripos_error.phpt @@ -9,22 +9,28 @@ Test stripos() function : error conditions echo "*** Testing stripos() function: error conditions ***\n"; -echo "\n-- Offset beyond the end of the string --"; -var_dump( stripos("Hello World", "o", 12) ); +echo "\n-- Offset beyond the end of the string --\n"; +try { + stripos("Hello World", "o", 12); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} -echo "\n-- Offset before the start of the string --"; -var_dump( stripos("Hello World", "o", -12) ); +echo "\n-- Offset before the start of the string --\n"; +try { + stripos("Hello World", "o", -12); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} echo "*** Done ***"; ?> ---EXPECTF-- +--EXPECT-- *** Testing stripos() function: error conditions *** -- Offset beyond the end of the string -- -Warning: stripos(): Offset not contained in string in %s on line %d -bool(false) +Offset not contained in string -- Offset before the start of the string -- -Warning: stripos(): Offset not contained in string in %s on line %d -bool(false) +Offset not contained in string *** Done *** diff --git a/ext/standard/tests/strings/stripos_variation11.phpt b/ext/standard/tests/strings/stripos_variation11.phpt index 4f002ed0ca367..7a9c9ff9a06cf 100644 --- a/ext/standard/tests/strings/stripos_variation11.phpt +++ b/ext/standard/tests/strings/stripos_variation11.phpt @@ -83,13 +83,13 @@ for($index = 0; $index < count($values); $index ++) { $haystack = $values[$index]; try { var_dump( stripos($values[$index], $values[$index]) ); - } catch (TypeError $e) { - echo $e->getMessage(), "\n"; + } catch (Error $e) { + echo get_class($e) . ": " . $e->getMessage(), "\n"; } try { var_dump( stripos($values[$index], $values[$index], 1) ); - } catch (TypeError $e) { - echo $e->getMessage(), "\n"; + } catch (Error $e) { + echo get_class($e) . ": " . $e->getMessage(), "\n"; } $counter ++; } @@ -126,70 +126,54 @@ bool(false) int(0) bool(false) -- Iteration 10 -- -stripos() expects parameter 1 to be string, array given -stripos() expects parameter 1 to be string, array given +TypeError: stripos() expects parameter 1 to be string, array given +TypeError: stripos() expects parameter 1 to be string, array given -- Iteration 11 -- -stripos() expects parameter 1 to be string, array given -stripos() expects parameter 1 to be string, array given +TypeError: stripos() expects parameter 1 to be string, array given +TypeError: stripos() expects parameter 1 to be string, array given -- Iteration 12 -- -stripos() expects parameter 1 to be string, array given -stripos() expects parameter 1 to be string, array given +TypeError: stripos() expects parameter 1 to be string, array given +TypeError: stripos() expects parameter 1 to be string, array given -- Iteration 13 -- -stripos() expects parameter 1 to be string, array given -stripos() expects parameter 1 to be string, array given +TypeError: stripos() expects parameter 1 to be string, array given +TypeError: stripos() expects parameter 1 to be string, array given -- Iteration 14 -- -stripos() expects parameter 1 to be string, array given -stripos() expects parameter 1 to be string, array given +TypeError: stripos() expects parameter 1 to be string, array given +TypeError: stripos() expects parameter 1 to be string, array given -- Iteration 15 -- int(0) bool(false) -- Iteration 16 -- int(0) - -Warning: stripos(): Offset not contained in string in %s on line %d -bool(false) +ValueError: Offset not contained in string -- Iteration 17 -- int(0) bool(false) -- Iteration 18 -- int(0) - -Warning: stripos(): Offset not contained in string in %s on line %d -bool(false) +ValueError: Offset not contained in string -- Iteration 19 -- int(0) bool(false) -- Iteration 20 -- int(0) - -Warning: stripos(): Offset not contained in string in %s on line %d -bool(false) +ValueError: Offset not contained in string -- Iteration 21 -- int(0) - -Warning: stripos(): Offset not contained in string in %s on line %d -bool(false) +ValueError: Offset not contained in string -- Iteration 22 -- int(0) - -Warning: stripos(): Offset not contained in string in %s on line %d -bool(false) +ValueError: Offset not contained in string -- Iteration 23 -- int(0) - -Warning: stripos(): Offset not contained in string in %s on line %d -bool(false) +ValueError: Offset not contained in string -- Iteration 24 -- -stripos() expects parameter 1 to be string, resource given -stripos() expects parameter 1 to be string, resource given +TypeError: stripos() expects parameter 1 to be string, resource given +TypeError: stripos() expects parameter 1 to be string, resource given -- Iteration 25 -- int(0) - -Warning: stripos(): Offset not contained in string in %s on line %d -bool(false) +ValueError: Offset not contained in string -- Iteration 26 -- int(0) - -Warning: stripos(): Offset not contained in string in %s on line %d -bool(false) +ValueError: Offset not contained in string *** Done *** diff --git a/ext/standard/tests/strings/stripos_variation7.phpt b/ext/standard/tests/strings/stripos_variation7.phpt index a21686876d31d..d2ac6551dbe1d 100644 --- a/ext/standard/tests/strings/stripos_variation7.phpt +++ b/ext/standard/tests/strings/stripos_variation7.phpt @@ -16,19 +16,22 @@ echo "-- With empty heredoc string --\n"; $empty_string = <<getMessage() . "\n"; +} var_dump( stripos($empty_string, FALSE) ); var_dump( stripos($empty_string, NULL) ); echo "*** Done ***"; ?> ---EXPECTF-- +--EXPECT-- *** Testing stripos() function: with heredoc strings *** -- With empty heredoc string -- int(0) - -Warning: stripos(): Offset not contained in string in %s on line %d -bool(false) +Offset not contained in string int(0) int(0) *** Done *** diff --git a/ext/standard/tests/strings/strpos.phpt b/ext/standard/tests/strings/strpos.phpt index 8e1a1a7472d18..2bc95a6c0a900 100644 Binary files a/ext/standard/tests/strings/strpos.phpt and b/ext/standard/tests/strings/strpos.phpt differ diff --git a/ext/standard/tests/strings/strripos_offset.phpt b/ext/standard/tests/strings/strripos_offset.phpt index 7dc0ce0d61dd0..4f4ab2bea4cbf 100644 --- a/ext/standard/tests/strings/strripos_offset.phpt +++ b/ext/standard/tests/strings/strripos_offset.phpt @@ -9,25 +9,36 @@ try { echo $e->getMessage(), "\n"; } -var_dump(strripos(1024, 1024, -PHP_INT_MAX)); -var_dump(strripos(1024, "te", -PHP_INT_MAX)); -var_dump(strripos(1024, 1024, -PHP_INT_MAX-1)); -var_dump(strripos(1024, "te", -PHP_INT_MAX-1)); - -echo "Done\n"; -?> ---EXPECTF-- -strripos() expects parameter 3 to be int, float given +try { + strripos(1024, 1024, -PHP_INT_MAX); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} -Warning: strripos(): Offset not contained in string in %s on line %d -bool(false) +try { + strripos(1024, "te", -PHP_INT_MAX); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} -Warning: strripos(): Offset not contained in string in %s on line %d -bool(false) +try { + strripos(1024, 1024, -PHP_INT_MAX-1); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} -Warning: strripos(): Offset not contained in string in %s on line %d -bool(false) +try { + strripos(1024, "te", -PHP_INT_MAX-1); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} -Warning: strripos(): Offset not contained in string in %s on line %d -bool(false) +echo "Done\n"; +?> +--EXPECT-- +strripos() expects parameter 3 to be int, float given +Offset not contained in string +Offset not contained in string +Offset not contained in string +Offset not contained in string Done diff --git a/ext/standard/tests/strings/strrpos_negative_offset.phpt b/ext/standard/tests/strings/strrpos_negative_offset.phpt index 940c2274f4e7f..17560f18f7fd6 100644 --- a/ext/standard/tests/strings/strrpos_negative_offset.phpt +++ b/ext/standard/tests/strings/strrpos_negative_offset.phpt @@ -8,15 +8,22 @@ strr[i]pos() function with negative offset var_dump(strrpos("haystack", "ka", -1)); var_dump(strrpos("haystack", 'a', -3)); var_dump(strrpos("haystack", 'a', -4)); - var_dump(@strrpos("haystack", 'h', -9)); - + try { + strrpos("haystack", 'h', -9); + } catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; + } var_dump(strripos("HAYSTHACk", 'ha', -9)); var_dump(strripos("HAYSTACK", 'h', -8)); var_dump(strripos("HAYSTACK", 'k', -1)); var_dump(strripos("HAYSTACK", "ka", -1)); var_dump(strripos("HAYSTACK", 'a', -3)); var_dump(strripos("HAYSTACK", 'a', -4)); - var_dump(@strripos("HAYSTACK", 'h', -9)); + try { + strripos("HAYSTACK", 'h', -9); + } catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; + } ?> --EXPECT-- int(0) @@ -25,11 +32,11 @@ int(7) bool(false) int(5) int(1) -bool(false) +Offset not contained in string int(0) int(0) int(7) bool(false) int(5) int(1) -bool(false) +Offset not contained in string diff --git a/ext/standard/tests/strings/strrpos_offset.phpt b/ext/standard/tests/strings/strrpos_offset.phpt index fdff39fdb2446..213cd24c6fdb7 100644 --- a/ext/standard/tests/strings/strrpos_offset.phpt +++ b/ext/standard/tests/strings/strrpos_offset.phpt @@ -9,25 +9,36 @@ try { echo $e->getMessage(), "\n"; } -var_dump(strrpos(1024, 1024, -PHP_INT_MAX)); -var_dump(strrpos(1024, "te", -PHP_INT_MAX)); -var_dump(strrpos(1024, 1024, -PHP_INT_MAX-1)); -var_dump(strrpos(1024, "te", -PHP_INT_MAX-1)); - -echo "Done\n"; -?> ---EXPECTF-- -strrpos() expects parameter 3 to be int, float given +try { + strrpos(1024, 1024, -PHP_INT_MAX); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} -Warning: strrpos(): Offset not contained in string in %s on line %d -bool(false) +try { + strrpos(1024, "te", -PHP_INT_MAX); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} -Warning: strrpos(): Offset not contained in string in %s on line %d -bool(false) +try { + strrpos(1024, 1024, -PHP_INT_MAX-1); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} -Warning: strrpos(): Offset not contained in string in %s on line %d -bool(false) +try { + strrpos(1024, "te", -PHP_INT_MAX-1); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} -Warning: strrpos(): Offset not contained in string in %s on line %d -bool(false) +echo "Done\n"; +?> +--EXPECT-- +strrpos() expects parameter 3 to be int, float given +Offset not contained in string +Offset not contained in string +Offset not contained in string +Offset not contained in string Done diff --git a/ext/standard/tests/strings/strrpos_variation11.phpt b/ext/standard/tests/strings/strrpos_variation11.phpt index 2fbe78e30acd0..2f8627d5ad240 100644 --- a/ext/standard/tests/strings/strrpos_variation11.phpt +++ b/ext/standard/tests/strings/strrpos_variation11.phpt @@ -83,13 +83,14 @@ for($index = 0; $index < count($values); $index ++) { $haystack = $values[$index]; try { var_dump( strrpos($values[$index], $values[$index]) ); - } catch (TypeError $e) { - echo $e->getMessage(), "\n"; + } catch (Error $e) { + echo get_class($e) . ": " . $e->getMessage(), "\n"; } + try { var_dump( strrpos($values[$index], $values[$index], 1) ); - } catch (TypeError $e) { - echo $e->getMessage(), "\n"; + } catch (Error $e) { + echo get_class($e) . ": " . $e->getMessage(), "\n"; } $counter ++; } @@ -126,70 +127,54 @@ bool(false) int(0) bool(false) -- Iteration 10 -- -strrpos() expects parameter 1 to be string, array given -strrpos() expects parameter 1 to be string, array given +TypeError: strrpos() expects parameter 1 to be string, array given +TypeError: strrpos() expects parameter 1 to be string, array given -- Iteration 11 -- -strrpos() expects parameter 1 to be string, array given -strrpos() expects parameter 1 to be string, array given +TypeError: strrpos() expects parameter 1 to be string, array given +TypeError: strrpos() expects parameter 1 to be string, array given -- Iteration 12 -- -strrpos() expects parameter 1 to be string, array given -strrpos() expects parameter 1 to be string, array given +TypeError: strrpos() expects parameter 1 to be string, array given +TypeError: strrpos() expects parameter 1 to be string, array given -- Iteration 13 -- -strrpos() expects parameter 1 to be string, array given -strrpos() expects parameter 1 to be string, array given +TypeError: strrpos() expects parameter 1 to be string, array given +TypeError: strrpos() expects parameter 1 to be string, array given -- Iteration 14 -- -strrpos() expects parameter 1 to be string, array given -strrpos() expects parameter 1 to be string, array given +TypeError: strrpos() expects parameter 1 to be string, array given +TypeError: strrpos() expects parameter 1 to be string, array given -- Iteration 15 -- int(0) bool(false) -- Iteration 16 -- int(0) - -Warning: strrpos(): Offset not contained in string in %s on line %d -bool(false) +ValueError: Offset not contained in string -- Iteration 17 -- int(0) bool(false) -- Iteration 18 -- int(0) - -Warning: strrpos(): Offset not contained in string in %s on line %d -bool(false) +ValueError: Offset not contained in string -- Iteration 19 -- int(0) bool(false) -- Iteration 20 -- int(0) - -Warning: strrpos(): Offset not contained in string in %s on line %d -bool(false) +ValueError: Offset not contained in string -- Iteration 21 -- int(0) - -Warning: strrpos(): Offset not contained in string in %s on line %d -bool(false) +ValueError: Offset not contained in string -- Iteration 22 -- int(0) - -Warning: strrpos(): Offset not contained in string in %s on line %d -bool(false) +ValueError: Offset not contained in string -- Iteration 23 -- int(0) - -Warning: strrpos(): Offset not contained in string in %s on line %d -bool(false) +ValueError: Offset not contained in string -- Iteration 24 -- -strrpos() expects parameter 1 to be string, resource given -strrpos() expects parameter 1 to be string, resource given +TypeError: strrpos() expects parameter 1 to be string, resource given +TypeError: strrpos() expects parameter 1 to be string, resource given -- Iteration 25 -- int(0) - -Warning: strrpos(): Offset not contained in string in %s on line %d -bool(false) +ValueError: Offset not contained in string -- Iteration 26 -- int(0) - -Warning: strrpos(): Offset not contained in string in %s on line %d -bool(false) +ValueError: Offset not contained in string *** Done *** diff --git a/ext/standard/tests/strings/strrpos_variation7.phpt b/ext/standard/tests/strings/strrpos_variation7.phpt index d5aa8b561ccb5..9a02a4a0ec00f 100644 --- a/ext/standard/tests/strings/strrpos_variation7.phpt +++ b/ext/standard/tests/strings/strrpos_variation7.phpt @@ -16,19 +16,21 @@ echo "-- With empty heredoc string --\n"; $empty_string = <<getMessage() . "\n"; +} var_dump( strrpos($empty_string, FALSE) ); var_dump( strrpos($empty_string, NULL) ); echo "*** Done ***"; ?> ---EXPECTF-- +--EXPECT-- *** Testing strrpos() function: with heredoc strings *** -- With empty heredoc string -- int(0) - -Warning: strrpos(): Offset not contained in string in %s on line %d -bool(false) +Offset not contained in string int(0) int(0) *** Done *** diff --git a/ext/standard/tests/strings/substr_count_error.phpt b/ext/standard/tests/strings/substr_count_error.phpt index 246963d13b40e..9bdb3843ebce2 100644 --- a/ext/standard/tests/strings/substr_count_error.phpt +++ b/ext/standard/tests/strings/substr_count_error.phpt @@ -7,10 +7,18 @@ echo "\n*** Testing error conditions ***\n"; $str = 'abcdefghik'; /* offset before start */ -var_dump(substr_count($str, "t", -20)); +try { + substr_count($str, "t", -20); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} /* offset > size of the string */ -var_dump(substr_count($str, "t", 25)); +try { + substr_count($str, "t", 25); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} /* Using offset and length to go beyond the size of the string: Warning message expected, as length+offset > length of string */ @@ -24,12 +32,8 @@ echo "Done\n"; ?> --EXPECTF-- *** Testing error conditions *** - -Warning: substr_count(): Offset not contained in string in %s on line %d -bool(false) - -Warning: substr_count(): Offset not contained in string in %s on line %d -bool(false) +Offset not contained in string +Offset not contained in string Warning: substr_count(): Invalid length value in %s on line %d bool(false) diff --git a/ext/standard/tests/strings/uuencode.phpt b/ext/standard/tests/strings/uuencode.phpt index 8199a2ed0571b..f7d864bdfa44d 100644 --- a/ext/standard/tests/strings/uuencode.phpt +++ b/ext/standard/tests/strings/uuencode.phpt @@ -10,7 +10,11 @@ var_dump(convert_uudecode("!@#$%^YUGFDFGHJKLUYTFBNMLOYT")); var_dump(convert_uudecode($enc)); var_dump($enc = convert_uuencode("not very sophisticated")); var_dump(convert_uudecode($enc)); -var_dump(convert_uudecode(substr($enc, 0, -10))); +try { + convert_uudecode(substr($enc, 0, -10)); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} echo "Done\n"; ?> @@ -26,7 +30,5 @@ string(36) "6;F]T('9EconstDump(); -constant('A::protectedConst'); +try { + constant('A::protectedConst'); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} ?> ---EXPECTF-- +--EXPECT-- string(14) "protectedConst" string(14) "protectedConst" - -Warning: constant(): Couldn't find constant A::protectedConst in %s on line %d +Couldn't find constant A::protectedConst diff --git a/tests/classes/constants_visibility_003.phpt b/tests/classes/constants_visibility_003.phpt index 7c961695ed6ce..caa135f4e4bb3 100644 --- a/tests/classes/constants_visibility_003.phpt +++ b/tests/classes/constants_visibility_003.phpt @@ -14,11 +14,13 @@ class A { A::staticConstDump(); (new A())->constDump(); -constant('A::privateConst'); - +try { + constant('A::privateConst'); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} ?> ---EXPECTF-- +--EXPECT-- string(12) "privateConst" string(12) "privateConst" - -Warning: constant(): Couldn't find constant A::privateConst in %s on line %d +Couldn't find constant A::privateConst diff --git a/tests/lang/bug44827.phpt b/tests/lang/bug44827.phpt index d871cfd2a89fc..3a1e379f50591 100644 --- a/tests/lang/bug44827.phpt +++ b/tests/lang/bug44827.phpt @@ -7,10 +7,12 @@ Testfest Munich 2009 --FILE-- getMessage() . "\n"; +} ?> --EXPECTF-- Warning: Class constants cannot be defined or redefined in %s on line %d - -Warning: constant(): Couldn't find constant :: in %s on line %d -NULL +Couldn't find constant ::