diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 9ccb9da3a5058..047ca7da7f060 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -523,50 +523,76 @@ PHP_FUNCTION(spl_autoload_register) if (Z_TYPE_P(zcallable) == IS_ARRAY) { if (!obj_ptr && alfi.func_ptr && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) { if (do_throw) { - zend_throw_exception_ex(spl_ce_LogicException, 0, "Passed array specifies a non static method but no object (%s)", error); + zend_type_error("Passed array specifies a non static method but no object (%s)", error); } if (error) { efree(error); } zend_string_release_ex(func_name, 0); - RETURN_FALSE; + + if (do_throw) { + RETURN_THROWS(); + } else { + RETURN_FALSE; + } } else if (do_throw) { - zend_throw_exception_ex(spl_ce_LogicException, 0, "Passed array does not specify %s %smethod (%s)", alfi.func_ptr ? "a callable" : "an existing", !obj_ptr ? "static " : "", error); + zend_type_error("Passed array does not specify %s %smethod (%s)", + alfi.func_ptr ? "a callable" : "an existing", !obj_ptr ? "static " : "", error); } if (error) { efree(error); } zend_string_release_ex(func_name, 0); - RETURN_FALSE; + + if (do_throw) { + RETURN_THROWS(); + } else { + RETURN_FALSE; + } } else if (Z_TYPE_P(zcallable) == IS_STRING) { if (do_throw) { - zend_throw_exception_ex(spl_ce_LogicException, 0, "Function '%s' not %s (%s)", ZSTR_VAL(func_name), alfi.func_ptr ? "callable" : "found", error); + zend_type_error("Function '%s' not %s (%s)", ZSTR_VAL(func_name), alfi.func_ptr ? "callable" : "found", error); } if (error) { efree(error); } zend_string_release_ex(func_name, 0); - RETURN_FALSE; + + if (do_throw) { + RETURN_THROWS(); + } else { + RETURN_FALSE; + } } else { if (do_throw) { - zend_throw_exception_ex(spl_ce_LogicException, 0, "Illegal value passed (%s)", error); + zend_type_error("Expected callable as first argument (%s)", error); } if (error) { efree(error); } zend_string_release_ex(func_name, 0); - RETURN_FALSE; + + if (do_throw) { + RETURN_THROWS(); + } else { + RETURN_FALSE; + } } } else if (fcc.function_handler->type == ZEND_INTERNAL_FUNCTION && fcc.function_handler->internal_function.handler == zif_spl_autoload_call) { if (do_throw) { - zend_throw_exception_ex(spl_ce_LogicException, 0, "Function spl_autoload_call() cannot be registered"); + zend_throw_error(NULL, "Function spl_autoload_call() cannot be registered"); } if (error) { efree(error); } zend_string_release_ex(func_name, 0); - RETURN_FALSE; + + if (do_throw) { + RETURN_THROWS(); + } else { + RETURN_FALSE; + } } alfi.ce = fcc.calling_scope; alfi.func_ptr = fcc.function_handler; @@ -688,14 +714,14 @@ PHP_FUNCTION(spl_autoload_unregister) } if (!zend_is_callable_ex(zcallable, NULL, IS_CALLABLE_CHECK_SYNTAX_ONLY, &func_name, &fcc, &error)) { - zend_throw_exception_ex(spl_ce_LogicException, 0, "Unable to unregister invalid function (%s)", error); + zend_throw_error(NULL, "Unable to unregister invalid function (%s)", error); if (error) { efree(error); } if (func_name) { zend_string_release_ex(func_name, 0); } - RETURN_FALSE; + RETURN_THROWS(); } obj_ptr = fcc.object; if (error) { diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index cbc40eafe8834..655789b98bed4 100644 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -298,7 +298,7 @@ static zval *spl_array_get_dimension_ptr(int check_inherited, spl_array_object * } if ((type == BP_VAR_W || type == BP_VAR_RW) && intern->nApplyCount > 0) { - zend_error(E_WARNING, "Modification of ArrayObject during sorting is prohibited"); + zend_throw_error(NULL, "Modification of ArrayObject during sorting is prohibited"); return &EG(error_zval); } @@ -386,9 +386,8 @@ static zval *spl_array_get_dimension_ptr(int check_inherited, spl_array_object * ZVAL_DEREF(offset); goto try_again; default: - zend_error(E_WARNING, "Illegal offset type"); - return (type == BP_VAR_W || type == BP_VAR_RW) ? - &EG(error_zval) : &EG(uninitialized_zval); + zend_type_error("Must be int|string, %s given", zend_zval_type_name(offset)); + return NULL; } } /* }}} */ @@ -446,7 +445,8 @@ static zval *spl_array_read_dimension(zend_object *object, zval *offset, int typ return spl_array_read_dimension_ex(1, object, offset, type, rv); } /* }}} */ -static void spl_array_write_dimension_ex(int check_inherited, zend_object *object, zval *offset, zval *value) /* {{{ */ +static void spl_array_write_dimension_ex(int check_inherited, zend_object *object, + zval *offset, zval *value, uint32_t offset_arg_num) /* {{{ */ { spl_array_object *intern = spl_array_from_obj(object); zend_long index; @@ -467,7 +467,7 @@ static void spl_array_write_dimension_ex(int check_inherited, zend_object *objec } if (intern->nApplyCount > 0) { - zend_error(E_WARNING, "Modification of ArrayObject during sorting is prohibited"); + zend_throw_error(NULL, "Modification of ArrayObject during sorting is prohibited"); return; } @@ -510,15 +510,23 @@ static void spl_array_write_dimension_ex(int check_inherited, zend_object *objec ZVAL_DEREF(offset); goto try_again; default: - zend_error(E_WARNING, "Illegal offset type"); zval_ptr_dtor(value); + /* If offset_arg_num is 0 this mean the offset comes from an index use in [offset] */ + if (offset_arg_num == 0) { + zend_type_error("Offsets must be int|string, %s given", + zend_zval_type_name(offset)); + } else { + zend_argument_type_error(offset_arg_num, "must be int|string, %s given", + zend_zval_type_name(offset)); + } return; } } /* }}} */ static void spl_array_write_dimension(zend_object *object, zval *offset, zval *value) /* {{{ */ { - spl_array_write_dimension_ex(1, object, offset, value); + /* Pass 0 as offset arg position to inform it comes from this handler */ + spl_array_write_dimension_ex(1, object, offset, value, 0); } /* }}} */ static void spl_array_unset_dimension_ex(int check_inherited, zend_object *object, zval *offset) /* {{{ */ @@ -535,7 +543,7 @@ static void spl_array_unset_dimension_ex(int check_inherited, zend_object *objec } if (intern->nApplyCount > 0) { - zend_error(E_WARNING, "Modification of ArrayObject during sorting is prohibited"); + zend_throw_error(NULL, "Modification of ArrayObject during sorting is prohibited"); return; } @@ -596,7 +604,7 @@ static void spl_array_unset_dimension_ex(int check_inherited, zend_object *objec ZVAL_DEREF(offset); goto try_again; default: - zend_error(E_WARNING, "Illegal offset type"); + zend_type_error("Must be int|string, %s given", zend_zval_type_name(offset)); return; } } /* }}} */ @@ -672,7 +680,7 @@ static int spl_array_has_dimension_ex(int check_inherited, zend_object *object, ZVAL_DEREF(offset); goto try_again; default: - zend_error(E_WARNING, "Illegal offset type"); + zend_type_error("Must be int|string, %s given", zend_zval_type_name(offset)); return 0; } @@ -733,7 +741,7 @@ SPL_METHOD(Array, offsetSet) if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz", &index, &value) == FAILURE) { RETURN_THROWS(); } - spl_array_write_dimension_ex(0, Z_OBJ_P(ZEND_THIS), index, value); + spl_array_write_dimension_ex(0, Z_OBJ_P(ZEND_THIS), index, value, 1); } /* }}} */ void spl_array_iterator_append(zval *object, zval *append_value) /* {{{ */ @@ -1103,9 +1111,14 @@ static void spl_array_it_rewind(zend_object_iterator *iter) /* {{{ */ /* }}} */ /* {{{ spl_array_set_array */ -static void spl_array_set_array(zval *object, spl_array_object *intern, zval *array, zend_long ar_flags, int just_array) { +static void spl_array_set_array(zval *object, spl_array_object *intern, zval *array, + zend_long ar_flags, int just_array, uint32_t arg_num) { if (Z_TYPE_P(array) != IS_OBJECT && Z_TYPE_P(array) != IS_ARRAY) { - zend_throw_exception(spl_ce_InvalidArgumentException, "Passed variable is not an array or object", 0); + if (arg_num == 0) { + zend_type_error("Passed variable must be array|object, %s given", zend_zval_type_name(array)); + } else { + zend_argument_type_error(arg_num, "must be array|object, %s given", zend_zval_type_name(array)); + } return; } @@ -1134,9 +1147,13 @@ static void spl_array_set_array(zval *object, spl_array_object *intern, zval *ar } else { zend_object_get_properties_t handler = Z_OBJ_HANDLER_P(array, get_properties); if (handler != zend_std_get_properties) { - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, - "Overloaded object of type %s is not compatible with %s", - ZSTR_VAL(Z_OBJCE_P(array)->name), ZSTR_VAL(intern->std.ce->name)); + if (arg_num == 0) { + zend_type_error("Overloaded object of type %s must be compatible with %s", + ZSTR_VAL(Z_OBJCE_P(array)->name), ZSTR_VAL(intern->std.ce->name)); + } else { + zend_argument_type_error(arg_num, "must be compatible with %s", + ZSTR_VAL(intern->std.ce->name)); + } return; } zval_ptr_dtor(&intern->array); @@ -1167,7 +1184,7 @@ zend_object_iterator *spl_array_get_iterator(zend_class_entry *ce, zval *object, spl_array_object *array_object = Z_SPLARRAY_P(object); if (by_ref && (array_object->ar_flags & SPL_ARRAY_OVERLOADED_CURRENT)) { - zend_throw_exception(spl_ce_RuntimeException, "An iterator cannot be used with foreach by reference", 0); + zend_throw_error(NULL, "An iterator cannot be used with foreach by reference"); return NULL; } @@ -1211,7 +1228,7 @@ SPL_METHOD(Array, __construct) ar_flags &= ~SPL_ARRAY_INT_MASK; - spl_array_set_array(object, intern, array, ar_flags, ZEND_NUM_ARGS() == 1); + spl_array_set_array(object, intern, array, ar_flags, ZEND_NUM_ARGS() == 1, 1); } /* }}} */ @@ -1236,7 +1253,7 @@ SPL_METHOD(ArrayIterator, __construct) ar_flags &= ~SPL_ARRAY_INT_MASK; - spl_array_set_array(object, intern, array, ar_flags, ZEND_NUM_ARGS() == 1); + spl_array_set_array(object, intern, array, ar_flags, ZEND_NUM_ARGS() == 1, 1); } /* }}} */ @@ -1315,12 +1332,12 @@ SPL_METHOD(Array, exchangeArray) } if (intern->nApplyCount > 0) { - zend_error(E_WARNING, "Modification of ArrayObject during sorting is prohibited"); + zend_throw_error(NULL, "Modification of ArrayObject during sorting is prohibited"); return; } RETVAL_ARR(zend_array_dup(spl_array_get_hash_table(intern))); - spl_array_set_array(object, intern, array, 0L, 1); + spl_array_set_array(object, intern, array, 0L, 1, 1); } /* }}} */ @@ -1380,7 +1397,8 @@ SPL_METHOD(Array, seek) return; /* ok */ } } - zend_throw_exception_ex(spl_ce_OutOfBoundsException, 0, "Seek position " ZEND_LONG_FMT " is out of range", opos); + zend_argument_value_error(1, "position " ZEND_LONG_FMT " is out of range", opos); + RETURN_THROWS(); } /* }}} */ static zend_long spl_array_object_count_elements_helper(spl_array_object *intern) /* {{{ */ @@ -1455,7 +1473,7 @@ static void spl_array_method(INTERNAL_FUNCTION_PARAMETERS, char *fname, int fnam intern->nApplyCount--; } else if (use_arg == SPL_ARRAY_METHOD_MAY_USER_ARG) { if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "|z", &arg) == FAILURE) { - zend_throw_exception(spl_ce_BadMethodCallException, "Function expects one argument at most", 0); + zend_argument_count_error("Function expects one argument at most"); goto exit; } if (arg) { @@ -1466,7 +1484,7 @@ static void spl_array_method(INTERNAL_FUNCTION_PARAMETERS, char *fname, int fnam intern->nApplyCount--; } else { if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "z", &arg) == FAILURE) { - zend_throw_exception(spl_ce_BadMethodCallException, "Function expects exactly one argument", 0); + zend_argument_count_error("Function expects exactly one argument"); goto exit; } ZVAL_COPY_VALUE(¶ms[1], arg); @@ -1732,7 +1750,7 @@ SPL_METHOD(Array, unserialize) } if (intern->nApplyCount > 0) { - zend_error(E_WARNING, "Modification of ArrayObject during sorting is prohibited"); + zend_throw_error(NULL, "Modification of ArrayObject during sorting is prohibited"); return; } @@ -1788,7 +1806,7 @@ SPL_METHOD(Array, unserialize) ZVAL_NULL(array); SEPARATE_ARRAY(&intern->array); } else { - spl_array_set_array(object, intern, array, 0L, 1); + spl_array_set_array(object, intern, array, 0L, 1, 0); } if (*p != ';') { @@ -1817,6 +1835,7 @@ SPL_METHOD(Array, unserialize) outexcept: PHP_VAR_UNSERIALIZE_DESTROY(var_hash); + /* TODO Use standard Error? */ zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "Error at offset " ZEND_LONG_FMT " of %zd bytes", (zend_long)((char*)p - buf), buf_len); RETURN_THROWS(); @@ -1884,7 +1903,7 @@ SPL_METHOD(Array, __unserialize) zval_ptr_dtor(&intern->array); ZVAL_UNDEF(&intern->array); } else { - spl_array_set_array(ZEND_THIS, intern, storage_zv, 0L, 1); + spl_array_set_array(ZEND_THIS, intern, storage_zv, 0L, 1, 0); } object_properties_load(&intern->std, Z_ARRVAL_P(members_zv)); diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index af7185ac7113b..0ff3ced745444 100644 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -206,7 +206,7 @@ static inline void spl_filesystem_object_get_file_name(spl_filesystem_object *in case SPL_FS_INFO: case SPL_FS_FILE: if (!intern->file_name) { - php_error_docref(NULL, E_ERROR, "Object not initialized"); + zend_throw_error(NULL, "Object not initialized"); } break; case SPL_FS_DIR: @@ -290,7 +290,7 @@ static int spl_filesystem_file_open(spl_filesystem_object *intern, int use_inclu if (Z_TYPE(tmp) == IS_TRUE) { intern->u.file.open_mode = NULL; intern->file_name = NULL; - zend_throw_exception_ex(spl_ce_LogicException, 0, "Cannot use SplFileObject with directories"); + zend_throw_error(NULL, "Cannot use SplFileObject with directories"); return FAILURE; } @@ -428,7 +428,8 @@ void spl_filesystem_info_set_filename(spl_filesystem_object *intern, char *path, intern->_path = estrndup(path, intern->_path_len); } /* }}} */ -static spl_filesystem_object *spl_filesystem_object_create_info(spl_filesystem_object *source, char *file_path, size_t file_path_len, int use_copy, zend_class_entry *ce, zval *return_value) /* {{{ */ +static spl_filesystem_object *spl_filesystem_object_create_info(spl_filesystem_object *source, + char *file_path, size_t file_path_len, int use_copy, zend_class_entry *ce, zval *return_value) /* {{{ */ { spl_filesystem_object *intern; zval arg1; @@ -436,10 +437,11 @@ static spl_filesystem_object *spl_filesystem_object_create_info(spl_filesystem_o if (!file_path || !file_path_len) { #if defined(PHP_WIN32) - zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Cannot create SplFileInfo for empty path"); + zend_value_error("Path cannot be empty"); if (file_path && !use_copy) { efree(file_path); } + return NULL; #else if (file_path && !use_copy) { efree(file_path); @@ -714,18 +716,18 @@ void spl_filesystem_object_construct(INTERNAL_FUNCTION_PARAMETERS, zend_long cto flags |= SPL_FILE_DIR_UNIXPATHS; } if (parsed == FAILURE) { - return; + RETURN_THROWS(); } if (!len) { - zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Directory name must not be empty."); + zend_argument_value_error(1, "cannot be empty"); return; } intern = Z_SPLFILESYSTEM_P(ZEND_THIS); if (intern->_path) { /* object is already initialized */ - php_error_docref(NULL, E_WARNING, "Directory object is already initialized"); + zend_throw_error(NULL, "Directory object is already initialized"); return; } intern->flags = flags; @@ -850,7 +852,7 @@ SPL_METHOD(DirectoryIterator, seek) valid = zend_is_true(&retval); zval_ptr_dtor(&retval); if (!valid) { - zend_throw_exception_ex(spl_ce_OutOfBoundsException, 0, "Seek position " ZEND_LONG_FMT " is out of range", pos); + zend_argument_value_error(1, "position " ZEND_LONG_FMT " is out of range", pos); RETURN_THROWS(); } zend_call_method_with_0_params(Z_OBJ_P(ZEND_THIS), Z_OBJCE_P(ZEND_THIS), &intern->u.dir.func_next, "next", NULL); @@ -1239,21 +1241,18 @@ SPL_METHOD(SplFileInfo, getLinkTarget) spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(ZEND_THIS); ssize_t ret; char buff[MAXPATHLEN]; - zend_error_handling error_handling; if (zend_parse_parameters_none() == FAILURE) { RETURN_THROWS(); } - zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling); - if (intern->file_name == NULL) { spl_filesystem_object_get_file_name(intern); } #if defined(PHP_WIN32) || HAVE_SYMLINK if (intern->file_name == NULL) { - php_error_docref(NULL, E_WARNING, "Empty filename"); - RETURN_FALSE; + zend_value_error("Filename cannot be empty"); + RETURN_THROWS(); } else if (!IS_ABSOLUTE_PATH(intern->file_name, intern->file_name_len)) { char expanded_path[MAXPATHLEN]; if (!expand_filepath_with_mode(intern->file_name, expanded_path, NULL, 0, CWD_EXPAND )) { @@ -1277,8 +1276,6 @@ SPL_METHOD(SplFileInfo, getLinkTarget) RETVAL_STRINGL(buff, ret); } - - zend_restore_error_handling(&error_handling); } /* }}} */ @@ -1605,7 +1602,7 @@ SPL_METHOD(GlobIterator, count) RETURN_LONG(php_glob_stream_get_count(intern->u.dir.dirp, NULL)); } else { /* should not happen */ - php_error_docref(NULL, E_ERROR, "GlobIterator lost glob state"); + zend_throw_error(NULL, "GlobIterator lost glob state"); } } /* }}} */ @@ -2180,7 +2177,7 @@ static int spl_filesystem_file_read_line(zval * this_ptr, spl_filesystem_object static void spl_filesystem_file_rewind(zval * this_ptr, spl_filesystem_object *intern) /* {{{ */ { if(!intern->u.file.stream) { - zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized"); + zend_throw_error(NULL, "Object not initialized"); return; } if (-1 == php_stream_rewind(intern->u.file.stream)) { @@ -2312,7 +2309,7 @@ SPL_METHOD(SplFileObject, eof) } if(!intern->u.file.stream) { - zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized"); + zend_throw_error(NULL, "Object not initialized"); RETURN_THROWS(); } @@ -2350,7 +2347,7 @@ SPL_METHOD(SplFileObject, fgets) } if(!intern->u.file.stream) { - zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized"); + zend_throw_error(NULL, "Object not initialized"); RETURN_THROWS(); } @@ -2371,7 +2368,7 @@ SPL_METHOD(SplFileObject, current) } if(!intern->u.file.stream) { - zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized"); + zend_throw_error(NULL, "Object not initialized"); RETURN_THROWS(); } @@ -2460,7 +2457,7 @@ SPL_METHOD(SplFileObject, setMaxLineLen) } if (max_len < 0) { - zend_throw_exception_ex(spl_ce_DomainException, 0, "Maximum line length must be greater than or equal zero"); + zend_argument_value_error(1, "must be greater than or equal to 0"); RETURN_THROWS(); } @@ -2523,7 +2520,7 @@ SPL_METHOD(SplFileObject, fgetcsv) if (zend_parse_parameters(ZEND_NUM_ARGS(), "|sss", &delim, &d_len, &enclo, &e_len, &esc, &esc_len) == SUCCESS) { if(!intern->u.file.stream) { - zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized"); + zend_throw_error(NULL, "Object not initialized"); RETURN_THROWS(); } @@ -2531,29 +2528,29 @@ SPL_METHOD(SplFileObject, fgetcsv) { case 3: if (esc_len > 1) { - php_error_docref(NULL, E_WARNING, "escape must be empty or a single character"); - RETURN_FALSE; + zend_argument_value_error(3, "must be empty or a single character"); + RETURN_THROWS(); } if (esc_len == 0) { escape = PHP_CSV_NO_ESCAPE; } else { escape = (unsigned char) esc[0]; } - /* no break */ + /* explicit fallthrough */ case 2: if (e_len != 1) { - php_error_docref(NULL, E_WARNING, "enclosure must be a character"); - RETURN_FALSE; + zend_argument_value_error(2, "must be a character"); + RETURN_THROWS(); } enclosure = enclo[0]; - /* no break */ + /* explicit fallthrough */ case 1: if (d_len != 1) { - php_error_docref(NULL, E_WARNING, "delimiter must be a character"); - RETURN_FALSE; + zend_argument_value_error(1, "must be a character"); + RETURN_THROWS(); } delimiter = delim[0]; - /* no break */ + /* explicit fallthrough */ case 0: break; } @@ -2586,24 +2583,24 @@ SPL_METHOD(SplFileObject, fputcsv) escape = (unsigned char) esc[0]; break; default: - php_error_docref(NULL, E_WARNING, "escape must be empty or a single character"); - RETURN_FALSE; + zend_argument_value_error(3, "must be empty or a single character"); + RETURN_THROWS(); } - /* no break */ + /* explicit fallthrough */ case 3: if (e_len != 1) { - php_error_docref(NULL, E_WARNING, "enclosure must be a character"); - RETURN_FALSE; + zend_argument_value_error(3, "must be a character"); + RETURN_THROWS(); } enclosure = enclo[0]; - /* no break */ + /* explicit fallthrough */ case 2: if (d_len != 1) { - php_error_docref(NULL, E_WARNING, "delimiter must be a character"); - RETURN_FALSE; + zend_argument_value_error(2, "must be a character"); + RETURN_THROWS(); } delimiter = delim[0]; - /* no break */ + /* explicit fallthrough */ case 1: case 0: break; @@ -2639,24 +2636,24 @@ SPL_METHOD(SplFileObject, setCsvControl) escape = (unsigned char) esc[0]; break; default: - php_error_docref(NULL, E_WARNING, "escape must be empty or a single character"); - RETURN_FALSE; + zend_argument_value_error(3, "must be empty or a single character"); + RETURN_THROWS(); } - /* no break */ + /* explicit fallthrough */ case 2: if (e_len != 1) { - php_error_docref(NULL, E_WARNING, "enclosure must be a character"); - RETURN_FALSE; + zend_argument_value_error(2, "must be a character"); + RETURN_THROWS(); } enclosure = enclo[0]; - /* no break */ + /* explicit fallthrough */ case 1: if (d_len != 1) { - php_error_docref(NULL, E_WARNING, "delimiter must be a character"); - RETURN_FALSE; + zend_argument_value_error(1, "must be a character"); + RETURN_THROWS(); } delimiter = delim[0]; - /* no break */ + /* explicit fallthrough */ case 0: break; } @@ -2705,7 +2702,7 @@ SPL_METHOD(SplFileObject, fflush) spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(ZEND_THIS); if(!intern->u.file.stream) { - zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized"); + zend_throw_error(NULL, "Object not initialized"); RETURN_THROWS(); } @@ -2720,7 +2717,7 @@ SPL_METHOD(SplFileObject, ftell) zend_long ret; if(!intern->u.file.stream) { - zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized"); + zend_throw_error(NULL, "Object not initialized"); RETURN_THROWS(); } @@ -2745,7 +2742,7 @@ SPL_METHOD(SplFileObject, fseek) } if(!intern->u.file.stream) { - zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized"); + zend_throw_error(NULL, "Object not initialized"); RETURN_THROWS(); } @@ -2762,7 +2759,7 @@ SPL_METHOD(SplFileObject, fgetc) int result; if(!intern->u.file.stream) { - zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized"); + zend_throw_error(NULL, "Object not initialized"); RETURN_THROWS(); } @@ -2790,7 +2787,7 @@ SPL_METHOD(SplFileObject, fpassthru) spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(ZEND_THIS); if(!intern->u.file.stream) { - zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized"); + zend_throw_error(NULL, "Object not initialized"); RETURN_THROWS(); } @@ -2804,7 +2801,7 @@ SPL_METHOD(SplFileObject, fscanf) spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(ZEND_THIS); if(!intern->u.file.stream) { - zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized"); + zend_throw_error(NULL, "Object not initialized"); RETURN_THROWS(); } @@ -2830,7 +2827,7 @@ SPL_METHOD(SplFileObject, fwrite) } if(!intern->u.file.stream) { - zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized"); + zend_throw_error(NULL, "Object not initialized"); RETURN_THROWS(); } @@ -2864,13 +2861,13 @@ SPL_METHOD(SplFileObject, fread) } if(!intern->u.file.stream) { - zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized"); + zend_throw_error(NULL, "Object not initialized"); RETURN_THROWS(); } if (length <= 0) { - php_error_docref(NULL, E_WARNING, "Length parameter must be greater than 0"); - RETURN_FALSE; + zend_argument_value_error(1, "must be greater than 0"); + RETURN_THROWS(); } str = php_stream_read_to_str(intern->u.file.stream, length); @@ -2897,7 +2894,7 @@ SPL_METHOD(SplFileObject, ftruncate) } if(!intern->u.file.stream) { - zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized"); + zend_throw_error(NULL, "Object not initialized"); RETURN_THROWS(); } @@ -2920,12 +2917,12 @@ SPL_METHOD(SplFileObject, seek) RETURN_THROWS(); } if(!intern->u.file.stream) { - zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized"); + zend_throw_error(NULL, "Object not initialized"); RETURN_THROWS(); } if (line_pos < 0) { - zend_throw_exception_ex(spl_ce_LogicException, 0, "Can't seek file %s to negative line " ZEND_LONG_FMT, intern->file_name, line_pos); + zend_value_error("Can't seek file %s to negative line", intern->file_name); RETURN_THROWS(); } diff --git a/ext/spl/spl_dllist.c b/ext/spl/spl_dllist.c index c4fb6f292ed90..388c49b2c7bda 100644 --- a/ext/spl/spl_dllist.c +++ b/ext/spl/spl_dllist.c @@ -770,6 +770,7 @@ SPL_METHOD(SplDoublyLinkedList, offsetGet) spl_dllist_object *intern; spl_ptr_llist_element *element; + /* TODO Change this to int? */ if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &zindex) == FAILURE) { RETURN_THROWS(); } @@ -778,7 +779,7 @@ SPL_METHOD(SplDoublyLinkedList, offsetGet) index = spl_offset_convert_to_long(zindex); if (index < 0 || index >= intern->llist->count) { - zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid or out of range", 0); + zend_argument_value_error(1, "is out of range"); RETURN_THROWS(); } @@ -789,7 +790,8 @@ SPL_METHOD(SplDoublyLinkedList, offsetGet) ZVAL_COPY_DEREF(return_value, value); } else { - zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid", 0); + zend_argument_value_error(1, "is invalid"); + RETURN_THROWS(); } } /* }}} */ @@ -817,7 +819,7 @@ SPL_METHOD(SplDoublyLinkedList, offsetSet) index = spl_offset_convert_to_long(zindex); if (index < 0 || index >= intern->llist->count) { - zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid or out of range", 0); + zend_argument_value_error(1, "is out of range"); RETURN_THROWS(); } @@ -840,7 +842,7 @@ SPL_METHOD(SplDoublyLinkedList, offsetSet) } } else { zval_ptr_dtor(value); - zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid", 0); + zend_argument_value_error(1, "is invalid"); RETURN_THROWS(); } } @@ -865,7 +867,7 @@ SPL_METHOD(SplDoublyLinkedList, offsetUnset) llist = intern->llist; if (index < 0 || index >= intern->llist->count) { - zend_throw_exception(spl_ce_OutOfRangeException, "Offset out of range", 0); + zend_argument_value_error(1, "is out of range"); RETURN_THROWS(); } @@ -906,7 +908,7 @@ SPL_METHOD(SplDoublyLinkedList, offsetUnset) SPL_LLIST_DELREF(element); } else { - zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid", 0); + zend_argument_value_error(1, "is invalid"); RETURN_THROWS(); } } /* }}} */ @@ -1209,6 +1211,7 @@ SPL_METHOD(SplDoublyLinkedList, unserialize) error: PHP_VAR_UNSERIALIZE_DESTROY(var_hash); + /* TODO Convert to standard Error ? */ zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "Error at offset %zd of %zd bytes", ((char*)p - buf), buf_len); RETURN_THROWS(); @@ -1262,8 +1265,7 @@ SPL_METHOD(SplDoublyLinkedList, __unserialize) { if (!flags_zv || !storage_zv || !members_zv || Z_TYPE_P(flags_zv) != IS_LONG || Z_TYPE_P(storage_zv) != IS_ARRAY || Z_TYPE_P(members_zv) != IS_ARRAY) { - zend_throw_exception(spl_ce_UnexpectedValueException, - "Incomplete or ill-typed serialization data", 0); + zend_throw_error(NULL, "Incomplete or ill-typed serialization data"); RETURN_THROWS(); } @@ -1293,7 +1295,7 @@ SPL_METHOD(SplDoublyLinkedList, add) index = spl_offset_convert_to_long(zindex); if (index < 0 || index > intern->llist->count) { - zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid or out of range", 0); + zend_argument_value_error(1, "is out of range"); RETURN_THROWS(); } @@ -1357,7 +1359,7 @@ zend_object_iterator *spl_dllist_get_iterator(zend_class_entry *ce, zval *object spl_dllist_object *dllist_object = Z_SPLDLLIST_P(object); if (by_ref) { - zend_throw_exception(spl_ce_RuntimeException, "An iterator cannot be used with foreach by reference", 0); + zend_throw_error(NULL, "An iterator cannot be used with foreach by reference"); return NULL; } diff --git a/ext/spl/spl_fixedarray.c b/ext/spl/spl_fixedarray.c index ce3cd2635e420..403fac8777d4f 100644 --- a/ext/spl/spl_fixedarray.c +++ b/ext/spl/spl_fixedarray.c @@ -237,7 +237,7 @@ static zend_object *spl_fixedarray_object_new_ex(zend_class_entry *class_type, z } if (!parent) { /* this must never happen */ - php_error_docref(NULL, E_COMPILE_ERROR, "Internal compiler error, Class is not child of SplFixedArray"); + zend_throw_error(NULL, "Internal compiler error, Class is not child of SplFixedArray"); } funcs_ptr = class_type->iterator_funcs_ptr; @@ -307,25 +307,37 @@ static zend_object *spl_fixedarray_object_clone(zend_object *old_object) /* {{{ } /* }}} */ -static inline zval *spl_fixedarray_object_read_dimension_helper(spl_fixedarray_object *intern, zval *offset) /* {{{ */ +static inline zval *spl_fixedarray_object_read_dimension_helper(spl_fixedarray_object *intern, + zval *offset, uint32_t offset_arg_num) /* {{{ */ { zend_long index; /* we have to return NULL on error here to avoid memleak because of * ZE duplicating uninitialized_zval_ptr */ if (!offset) { - zend_throw_exception(spl_ce_RuntimeException, "Index invalid or out of range", 0); + zend_throw_error(NULL, "Must provided an index to read"); return NULL; } if (Z_TYPE_P(offset) != IS_LONG) { index = spl_offset_convert_to_long(offset); + if (index == -1) { + if (offset_arg_num == 0) { + zend_value_error("Offset must be numeric"); + } else { + zend_argument_value_error(offset_arg_num, "must be numeric"); + } + } } else { index = Z_LVAL_P(offset); } if (index < 0 || index >= intern->array.size) { - zend_throw_exception(spl_ce_RuntimeException, "Index invalid or out of range", 0); + if (offset_arg_num == 0) { + zend_value_error("Offset is out of range"); + } else { + zend_argument_value_error(offset_arg_num, "is out of range"); + } return NULL; } else { return &intern->array.elements[index]; @@ -339,6 +351,12 @@ static zval *spl_fixedarray_object_read_dimension(zend_object *object, zval *off { spl_fixedarray_object *intern; + if (!offset) { + /* This emits a Notice + Indirect modification of overloaded element of SplFixedArray has no effect */ + return &EG(uninitialized_zval); + } + intern = spl_fixed_array_from_obj(object); if (type == BP_VAR_IS && !spl_fixedarray_object_has_dimension(object, offset, 0)) { @@ -346,13 +364,7 @@ static zval *spl_fixedarray_object_read_dimension(zend_object *object, zval *off } if (intern->fptr_offset_get) { - zval tmp; - if (!offset) { - ZVAL_NULL(&tmp); - offset = &tmp; - } else { - SEPARATE_ARG_IF_REF(offset); - } + SEPARATE_ARG_IF_REF(offset); zend_call_method_with_1_params(object, intern->std.ce, &intern->fptr_offset_get, "offsetGet", rv, offset); zval_ptr_dtor(offset); if (!Z_ISUNDEF_P(rv)) { @@ -361,19 +373,16 @@ static zval *spl_fixedarray_object_read_dimension(zend_object *object, zval *off return &EG(uninitialized_zval); } - return spl_fixedarray_object_read_dimension_helper(intern, offset); + return spl_fixedarray_object_read_dimension_helper(intern, offset, 0); } /* }}} */ -static inline void spl_fixedarray_object_write_dimension_helper(spl_fixedarray_object *intern, zval *offset, zval *value) /* {{{ */ +static inline void spl_fixedarray_object_write_dimension_helper(spl_fixedarray_object *intern, + zval *offset, zval *value, uint32_t offset_arg_num) /* {{{ */ { zend_long index; - if (!offset) { - /* '$array[] = value' syntax is not supported */ - zend_throw_exception(spl_ce_RuntimeException, "Index invalid or out of range", 0); - return; - } + ZEND_ASSERT(offset != NULL); if (Z_TYPE_P(offset) != IS_LONG) { index = spl_offset_convert_to_long(offset); @@ -382,7 +391,11 @@ static inline void spl_fixedarray_object_write_dimension_helper(spl_fixedarray_o } if (index < 0 || index >= intern->array.size) { - zend_throw_exception(spl_ce_RuntimeException, "Index invalid or out of range", 0); + if (offset_arg_num == 0) { + zend_value_error("Offset is out of range"); + } else { + zend_argument_value_error(offset_arg_num, "is out of range"); + } return; } else { zval_ptr_dtor(&(intern->array.elements[index])); @@ -394,17 +407,17 @@ static inline void spl_fixedarray_object_write_dimension_helper(spl_fixedarray_o static void spl_fixedarray_object_write_dimension(zend_object *object, zval *offset, zval *value) /* {{{ */ { spl_fixedarray_object *intern; - zval tmp; + + /* '$array[] = value' syntax is not supported */ + if (!offset) { + zend_throw_error(NULL, "Dynamic allocation is forbidden"); + return; + } intern = spl_fixed_array_from_obj(object); if (intern->fptr_offset_set) { - if (!offset) { - ZVAL_NULL(&tmp); - offset = &tmp; - } else { - SEPARATE_ARG_IF_REF(offset); - } + SEPARATE_ARG_IF_REF(offset); SEPARATE_ARG_IF_REF(value); zend_call_method_with_2_params(object, intern->std.ce, &intern->fptr_offset_set, "offsetSet", NULL, offset, value); zval_ptr_dtor(value); @@ -412,11 +425,12 @@ static void spl_fixedarray_object_write_dimension(zend_object *object, zval *off return; } - spl_fixedarray_object_write_dimension_helper(intern, offset, value); + spl_fixedarray_object_write_dimension_helper(intern, offset, value, 0); } /* }}} */ -static inline void spl_fixedarray_object_unset_dimension_helper(spl_fixedarray_object *intern, zval *offset) /* {{{ */ +static inline void spl_fixedarray_object_unset_dimension_helper(spl_fixedarray_object *intern, + zval *offset, uint32_t offset_arg_num) /* {{{ */ { zend_long index; @@ -427,7 +441,11 @@ static inline void spl_fixedarray_object_unset_dimension_helper(spl_fixedarray_o } if (index < 0 || index >= intern->array.size) { - zend_throw_exception(spl_ce_RuntimeException, "Index invalid or out of range", 0); + if (offset_arg_num == 0) { + zend_value_error("Offset is out of range"); + } else { + zend_argument_value_error(offset_arg_num, "is out of range"); + } return; } else { zval_ptr_dtor(&(intern->array.elements[index])); @@ -449,7 +467,7 @@ static void spl_fixedarray_object_unset_dimension(zend_object *object, zval *off return; } - spl_fixedarray_object_unset_dimension_helper(intern, offset); + spl_fixedarray_object_unset_dimension_helper(intern, offset, 0); } /* }}} */ @@ -534,7 +552,7 @@ SPL_METHOD(SplFixedArray, __construct) } if (size < 0) { - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "array size cannot be less than zero"); + zend_argument_value_error(1, "must be greater than or equal to 0"); RETURN_THROWS(); } @@ -645,7 +663,8 @@ SPL_METHOD(SplFixedArray, fromArray) ZEND_HASH_FOREACH_KEY(Z_ARRVAL_P(data), num_index, str_index) { if (str_index != NULL || (zend_long)num_index < 0) { - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "array must contain only positive integer keys"); + /* TODO Better error message? */ + zend_value_error("array must contain only positive integer keys"); RETURN_THROWS(); } @@ -656,7 +675,7 @@ SPL_METHOD(SplFixedArray, fromArray) tmp = max_index + 1; if (tmp <= 0) { - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "integer overflow detected"); + zend_throw_error(NULL, "Integer overflow detected"); RETURN_THROWS(); } spl_fixedarray_init(&array, tmp); @@ -715,7 +734,7 @@ SPL_METHOD(SplFixedArray, setSize) } if (size < 0) { - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "array size cannot be less than zero"); + zend_argument_value_error(1, "must be greater than or equal to 0"); RETURN_THROWS(); } @@ -754,7 +773,7 @@ SPL_METHOD(SplFixedArray, offsetGet) } intern = Z_SPLFIXEDARRAY_P(ZEND_THIS); - value = spl_fixedarray_object_read_dimension_helper(intern, zindex); + value = spl_fixedarray_object_read_dimension_helper(intern, zindex, 1); if (value) { ZVAL_COPY_DEREF(return_value, value); @@ -775,7 +794,7 @@ SPL_METHOD(SplFixedArray, offsetSet) } intern = Z_SPLFIXEDARRAY_P(ZEND_THIS); - spl_fixedarray_object_write_dimension_helper(intern, zindex, value); + spl_fixedarray_object_write_dimension_helper(intern, zindex, value, 1); } /* }}} */ @@ -791,7 +810,7 @@ SPL_METHOD(SplFixedArray, offsetUnset) } intern = Z_SPLFIXEDARRAY_P(ZEND_THIS); - spl_fixedarray_object_unset_dimension_helper(intern, zindex); + spl_fixedarray_object_unset_dimension_helper(intern, zindex, 1); } /* }}} */ @@ -844,7 +863,7 @@ static zval *spl_fixedarray_it_get_current_data(zend_object_iterator *iter) /* { ZVAL_LONG(&zindex, object->current); - data = spl_fixedarray_object_read_dimension_helper(object, &zindex); + data = spl_fixedarray_object_read_dimension_helper(object, &zindex, 0); if (data == NULL) { data = &EG(uninitialized_zval); @@ -948,7 +967,7 @@ SPL_METHOD(SplFixedArray, current) ZVAL_LONG(&zindex, intern->current); - value = spl_fixedarray_object_read_dimension_helper(intern, &zindex); + value = spl_fixedarray_object_read_dimension_helper(intern, &zindex, 0); if (value) { ZVAL_COPY_DEREF(return_value, value); @@ -974,7 +993,7 @@ zend_object_iterator *spl_fixedarray_get_iterator(zend_class_entry *ce, zval *ob spl_fixedarray_it *iterator; if (by_ref) { - zend_throw_exception(spl_ce_RuntimeException, "An iterator cannot be used with foreach by reference", 0); + zend_throw_error(NULL, "An iterator cannot be used with foreach by reference"); return NULL; } diff --git a/ext/spl/spl_heap.c b/ext/spl/spl_heap.c index dcef01b5eb560..64ce8d3f4ffba 100644 --- a/ext/spl/spl_heap.c +++ b/ext/spl/spl_heap.c @@ -434,7 +434,7 @@ static zend_object *spl_heap_object_new_ex(zend_class_entry *class_type, zend_ob } if (!parent) { /* this must never happen */ - php_error_docref(NULL, E_COMPILE_ERROR, "Internal compiler error, Class is not child of SplHeap"); + zend_throw_error(NULL, "Internal compiler error, Class is not child of SplHeap"); } if (inherited) { @@ -602,7 +602,7 @@ SPL_METHOD(SplHeap, insert) intern = Z_SPLHEAP_P(ZEND_THIS); if (intern->heap->flags & SPL_HEAP_CORRUPTED) { - zend_throw_exception(spl_ce_RuntimeException, "Heap is corrupted, heap properties are no longer ensured.", 0); + zend_throw_error(NULL, "Heap is corrupted, heap properties are no longer ensured"); RETURN_THROWS(); } @@ -626,11 +626,12 @@ SPL_METHOD(SplHeap, extract) intern = Z_SPLHEAP_P(ZEND_THIS); if (intern->heap->flags & SPL_HEAP_CORRUPTED) { - zend_throw_exception(spl_ce_RuntimeException, "Heap is corrupted, heap properties are no longer ensured.", 0); + zend_throw_error(NULL, "Heap is corrupted, heap properties are no longer ensured"); RETURN_THROWS(); } if (spl_ptr_heap_delete_top(intern->heap, return_value, ZEND_THIS) == FAILURE) { + /* TODO change normal Error? */ zend_throw_exception(spl_ce_RuntimeException, "Can't extract from an empty heap", 0); RETURN_THROWS(); } @@ -652,7 +653,7 @@ SPL_METHOD(SplPriorityQueue, insert) intern = Z_SPLHEAP_P(ZEND_THIS); if (intern->heap->flags & SPL_HEAP_CORRUPTED) { - zend_throw_exception(spl_ce_RuntimeException, "Heap is corrupted, heap properties are no longer ensured.", 0); + zend_throw_error(NULL, "Heap is corrupted, heap properties are no longer ensured"); RETURN_THROWS(); } @@ -679,7 +680,7 @@ SPL_METHOD(SplPriorityQueue, extract) intern = Z_SPLHEAP_P(ZEND_THIS); if (intern->heap->flags & SPL_HEAP_CORRUPTED) { - zend_throw_exception(spl_ce_RuntimeException, "Heap is corrupted, heap properties are no longer ensured.", 0); + zend_throw_error(NULL, "Heap is corrupted, heap properties are no longer ensured"); RETURN_THROWS(); } @@ -707,7 +708,7 @@ SPL_METHOD(SplPriorityQueue, top) intern = Z_SPLHEAP_P(ZEND_THIS); if (intern->heap->flags & SPL_HEAP_CORRUPTED) { - zend_throw_exception(spl_ce_RuntimeException, "Heap is corrupted, heap properties are no longer ensured.", 0); + zend_throw_error(NULL, "Heap is corrupted, heap properties are no longer ensured"); RETURN_THROWS(); } @@ -736,7 +737,7 @@ SPL_METHOD(SplPriorityQueue, setExtractFlags) value &= SPL_PQUEUE_EXTR_MASK; if (!value) { - zend_throw_exception(spl_ce_RuntimeException, "Must specify at least one extract flag", 0); + zend_argument_value_error(1, "must specify at least one extract flag", 0); RETURN_THROWS(); } @@ -824,7 +825,7 @@ SPL_METHOD(SplHeap, top) intern = Z_SPLHEAP_P(ZEND_THIS); if (intern->heap->flags & SPL_HEAP_CORRUPTED) { - zend_throw_exception(spl_ce_RuntimeException, "Heap is corrupted, heap properties are no longer ensured.", 0); + zend_throw_error(NULL, "Heap is corrupted, heap properties are no longer ensured"); RETURN_THROWS(); } @@ -893,7 +894,7 @@ static zval *spl_heap_it_get_current_data(zend_object_iterator *iter) /* {{{ */ spl_heap_object *object = Z_SPLHEAP_P(&iter->data); if (object->heap->flags & SPL_HEAP_CORRUPTED) { - zend_throw_exception(spl_ce_RuntimeException, "Heap is corrupted, heap properties are no longer ensured.", 0); + zend_throw_error(NULL, "Heap is corrupted, heap properties are no longer ensured"); return NULL; } @@ -911,7 +912,7 @@ static zval *spl_pqueue_it_get_current_data(zend_object_iterator *iter) /* {{{ * spl_heap_object *object = Z_SPLHEAP_P(&iter->data); if (object->heap->flags & SPL_HEAP_CORRUPTED) { - zend_throw_exception(spl_ce_RuntimeException, "Heap is corrupted, heap properties are no longer ensured.", 0); + zend_throw_error(NULL, "Heap is corrupted, heap properties are no longer ensured"); return NULL; } @@ -940,7 +941,7 @@ static void spl_heap_it_move_forward(zend_object_iterator *iter) /* {{{ */ spl_heap_object *object = Z_SPLHEAP_P(&iter->data); if (object->heap->flags & SPL_HEAP_CORRUPTED) { - zend_throw_exception(spl_ce_RuntimeException, "Heap is corrupted, heap properties are no longer ensured.", 0); + zend_throw_error(NULL, "Heap is corrupted, heap properties are no longer ensured"); return; } @@ -1087,7 +1088,7 @@ zend_object_iterator *spl_heap_get_iterator(zend_class_entry *ce, zval *object, spl_heap_object *heap_object = Z_SPLHEAP_P(object); if (by_ref) { - zend_throw_exception(spl_ce_RuntimeException, "An iterator cannot be used with foreach by reference", 0); + zend_throw_error(NULL, "An iterator cannot be used with foreach by reference"); return NULL; } @@ -1112,7 +1113,7 @@ zend_object_iterator *spl_pqueue_get_iterator(zend_class_entry *ce, zval *object spl_heap_object *heap_object = Z_SPLHEAP_P(object); if (by_ref) { - zend_throw_exception(spl_ce_RuntimeException, "An iterator cannot be used with foreach by reference", 0); + zend_throw_error(NULL, "An iterator cannot be used with foreach by reference"); return NULL; } diff --git a/ext/spl/spl_iterators.c b/ext/spl/spl_iterators.c index 733d3ac7d5bcc..d12a40493cfb4 100644 --- a/ext/spl/spl_iterators.c +++ b/ext/spl/spl_iterators.c @@ -131,9 +131,8 @@ static inline spl_recursive_it_object *spl_recursive_it_from_obj(zend_object *ob do { \ spl_dual_it_object *it = Z_SPLDUAL_IT_P(objzval); \ if (it->dit_type == DIT_Unknown) { \ - zend_throw_exception_ex(spl_ce_LogicException, 0, \ - "The object is in an invalid state as the parent constructor was not called"); \ - RETURN_THROWS(); \ + zend_throw_error(NULL, "The object is in an invalid state as the parent constructor was not called"); \ + RETURN_THROWS(); \ } \ (var) = it; \ } while (0) @@ -141,8 +140,7 @@ static inline spl_recursive_it_object *spl_recursive_it_from_obj(zend_object *ob #define SPL_FETCH_SUB_ELEMENT(var, object, element) \ do { \ if(!(object)->iterators) { \ - zend_throw_exception_ex(spl_ce_LogicException, 0, \ - "The object is in an invalid state as the parent constructor was not called"); \ + zend_throw_error(NULL, "The object is in an invalid state as the parent constructor was not called"); \ return; \ } \ (var) = (object)->iterators[(object)->level].element; \ @@ -151,8 +149,7 @@ static inline spl_recursive_it_object *spl_recursive_it_from_obj(zend_object *ob #define SPL_FETCH_SUB_ELEMENT_ADDR(var, object, element) \ do { \ if(!(object)->iterators) { \ - zend_throw_exception_ex(spl_ce_LogicException, 0, \ - "The object is in an invalid state as the parent constructor was not called"); \ + zend_throw_error(NULL, "The object is in an invalid state as the parent constructor was not called"); \ RETURN_THROWS(); \ } \ (var) = &(object)->iterators[(object)->level].element; \ @@ -258,7 +255,7 @@ static void spl_recursive_it_move_forward_ex(spl_recursive_it_object *object, zv break; } object->iterators[object->level].state = RS_TEST; - /* break; */ + /* break; */ // wat? case RS_TEST: ce = object->iterators[object->level].ce; zobject = &object->iterators[object->level].zobject; @@ -343,8 +340,9 @@ static void spl_recursive_it_move_forward_ex(spl_recursive_it_object *object, zv if (Z_TYPE(child) == IS_UNDEF || Z_TYPE(child) != IS_OBJECT || !((ce = Z_OBJCE(child)) && instanceof_function(ce, spl_ce_RecursiveIterator))) { + zend_type_error("Return value of RecursiveIterator::getChildren() must be of type RecursiveIterator, %s returned", + zend_zval_type_name(&child)); zval_ptr_dtor(&child); - zend_throw_exception(spl_ce_UnexpectedValueException, "Objects returned by RecursiveIterator::getChildren() must implement RecursiveIterator", 0); return; } @@ -453,13 +451,13 @@ static zend_object_iterator *spl_recursive_it_get_iterator(zend_class_entry *ce, spl_recursive_it_object *object; if (by_ref) { - zend_throw_exception(spl_ce_RuntimeException, "An iterator cannot be used with foreach by reference", 0); + zend_throw_error(NULL, "An iterator cannot be used with foreach by reference"); return NULL; } iterator = emalloc(sizeof(spl_recursive_it_iterator)); object = Z_SPLRECURSIVE_IT_P(zobject); if (object->iterators == NULL) { - zend_error(E_ERROR, "The object to be iterated is in an invalid state: " + zend_throw_error(NULL, "The object to be iterated is in an invalid state: " "the parent constructor has not been called"); } @@ -529,7 +527,7 @@ static void spl_recursive_it_it_construct(INTERNAL_FUNCTION_PARAMETERS, zend_cla if (iterator) { zval_ptr_dtor(iterator); } - zend_throw_exception(spl_ce_InvalidArgumentException, "An instance of RecursiveIterator or IteratorAggregate creating it is required", 0); + zend_throw_error(NULL, "An instance of RecursiveIterator or IteratorAggregate creating it is required"); zend_restore_error_handling(&error_handling); return; } @@ -708,8 +706,7 @@ SPL_METHOD(RecursiveIteratorIterator, getSubIterator) } if(!object->iterators) { - zend_throw_exception_ex(spl_ce_LogicException, 0, - "The object is in an invalid state as the parent constructor was not called"); + zend_throw_error(NULL, "The object is in an invalid state as the parent constructor was not called"); RETURN_THROWS(); } @@ -848,7 +845,7 @@ SPL_METHOD(RecursiveIteratorIterator, setMaxDepth) RETURN_THROWS(); } if (max_depth < -1) { - zend_throw_exception(spl_ce_OutOfRangeException, "Parameter max_depth must be >= -1", 0); + zend_argument_value_error(1, "must be greater or equal than -1"); RETURN_THROWS(); } else if (max_depth > INT_MAX) { max_depth = INT_MAX; @@ -882,7 +879,9 @@ static zend_function *spl_recursive_it_get_method(zend_object **zobject, zend_st zval *zobj; if (!object->iterators) { - php_error_docref(NULL, E_ERROR, "The %s instance wasn't initialized properly", ZSTR_VAL((*zobject)->ce->name)); + zend_throw_error(NULL, "The %s instance wasn't initialized properly", + ZSTR_VAL((*zobject)->ce->name)); + return NULL; } zobj = &object->iterators[level].zobject; @@ -1084,7 +1083,7 @@ SPL_METHOD(RecursiveTreeIterator, setPrefixPart) } if (0 > part || part > 5) { - zend_throw_exception_ex(spl_ce_OutOfRangeException, 0, "Use RecursiveTreeIterator::PREFIX_* constant"); + zend_argument_value_error(2, "must be one of RecursiveTreeIterator::PREFIX_*"); RETURN_THROWS(); } @@ -1103,7 +1102,7 @@ SPL_METHOD(RecursiveTreeIterator, getPrefix) } if(!object->iterators) { - zend_throw_exception_ex(spl_ce_LogicException, 0, + zend_throw_error(NULL, "The object is in an invalid state as the parent constructor was not called"); RETURN_THROWS(); } @@ -1138,7 +1137,7 @@ SPL_METHOD(RecursiveTreeIterator, getEntry) } if(!object->iterators) { - zend_throw_exception_ex(spl_ce_LogicException, 0, + zend_throw_error(NULL, "The object is in an invalid state as the parent constructor was not called"); RETURN_THROWS(); } @@ -1157,7 +1156,7 @@ SPL_METHOD(RecursiveTreeIterator, getPostfix) } if(!object->iterators) { - zend_throw_exception_ex(spl_ce_LogicException, 0, + zend_throw_error(NULL, "The object is in an invalid state as the parent constructor was not called"); RETURN_THROWS(); } @@ -1179,7 +1178,7 @@ SPL_METHOD(RecursiveTreeIterator, current) } if(!object->iterators) { - zend_throw_exception_ex(spl_ce_LogicException, 0, + zend_throw_error(NULL, "The object is in an invalid state as the parent constructor was not called"); RETURN_THROWS(); } @@ -1325,7 +1324,7 @@ static zend_function *spl_dual_it_get_method(zend_object **object, zend_string * #define SPL_CHECK_CTOR(intern, classname) \ if (intern->dit_type == DIT_Unknown) { \ - zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Classes derived from %s must call %s::__construct()", \ + zend_throw_error(NULL, "Classes derived from %s must call %s::__construct()", \ ZSTR_VAL((spl_ce_##classname)->name), ZSTR_VAL((spl_ce_##classname)->name)); \ RETURN_THROWS(); \ } @@ -1357,7 +1356,8 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z intern = Z_SPLDUAL_IT_P(ZEND_THIS); if (intern->dit_type != DIT_Unknown) { - zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "%s::getIterator() must be called exactly once per instance", ZSTR_VAL(ce_base->name)); + zend_throw_error(NULL, "%s::getIterator() must be called exactly once per instance", + ZSTR_VAL(ce_base->name)); return NULL; } @@ -1370,11 +1370,11 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z return NULL; } if (intern->u.limit.offset < 0) { - zend_throw_exception(spl_ce_OutOfRangeException, "Parameter offset must be >= 0", 0); + zend_argument_value_error(1, "must be greater or equal to 0"); return NULL; } if (intern->u.limit.count < 0 && intern->u.limit.count != -1) { - zend_throw_exception(spl_ce_OutOfRangeException, "Parameter count must either be -1 or a value greater than or equal 0", 0); + zend_argument_value_error(2, "must be greater or equal to 0"); return NULL; } break; @@ -1386,7 +1386,7 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z return NULL; } if (spl_cit_check_flags(flags) != SUCCESS) { - zend_throw_exception(spl_ce_InvalidArgumentException, "Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER", 0); + zend_argument_value_error(2, "must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER"); return NULL; } intern->u.caching.flags |= flags & CIT_PUBLIC; @@ -1407,7 +1407,7 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z || !instanceof_function(ce, ce_cast) || !ce_cast->get_iterator ) { - zend_throw_exception(spl_ce_LogicException, "Class to downcast to not found or not base class or does not implement Traversable", 0); + zend_argument_type_error(1, "Class to downcast to not found or not base class or does not implement Traversable"); return NULL; } ce = ce_cast; @@ -1419,7 +1419,7 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z return NULL; } if (Z_TYPE(retval) != IS_OBJECT || !instanceof_function(Z_OBJCE(retval), zend_ce_traversable)) { - zend_throw_exception_ex(spl_ce_LogicException, 0, "%s::getIterator() must return an object that implements Traversable", ZSTR_VAL(ce->name)); + zend_type_error("Return value of %s::getIterator() must be Traversable", ZSTR_VAL(ce->name)); return NULL; } zobject = &retval; @@ -1451,7 +1451,7 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z return NULL; } if (mode < 0 || mode >= REGIT_MODE_MAX) { - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Illegal mode " ZEND_LONG_FMT, mode); + zend_argument_value_error(3, "is illegal"); return NULL; } intern->u.regex.mode = mode; @@ -2045,7 +2045,7 @@ SPL_METHOD(RegexIterator, setMode) } if (mode < 0 || mode >= REGIT_MODE_MAX) { - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Illegal mode " ZEND_LONG_FMT, mode); + zend_value_error("Illegal mode " ZEND_LONG_FMT, mode); RETURN_THROWS(); } @@ -2331,11 +2331,11 @@ static inline void spl_limit_it_seek(spl_dual_it_object *intern, zend_long pos) spl_dual_it_free(intern); if (pos < intern->u.limit.offset) { - zend_throw_exception_ex(spl_ce_OutOfBoundsException, 0, "Cannot seek to " ZEND_LONG_FMT " which is below the offset " ZEND_LONG_FMT, pos, intern->u.limit.offset); + zend_value_error("Seek position is out of bounds"); return; } if (pos >= intern->u.limit.offset + intern->u.limit.count && intern->u.limit.count != -1) { - zend_throw_exception_ex(spl_ce_OutOfBoundsException, 0, "Cannot seek to " ZEND_LONG_FMT " which is behind offset " ZEND_LONG_FMT " plus count " ZEND_LONG_FMT, pos, intern->u.limit.offset, intern->u.limit.count); + zend_value_error("Seek position is out of bounds"); return; } if (pos != intern->current.pos && instanceof_function(intern->inner.ce, spl_ce_SeekableIterator)) { @@ -2637,6 +2637,7 @@ SPL_METHOD(CachingIterator, __toString) SPL_FETCH_AND_CHECK_DUAL_IT(intern, ZEND_THIS); if (!(intern->u.caching.flags & (CIT_CALL_TOSTRING|CIT_TOSTRING_USE_KEY|CIT_TOSTRING_USE_CURRENT|CIT_TOSTRING_USE_INNER))) { + // Todo conversion zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "%s does not fetch string value (see CachingIterator::__construct)", ZSTR_VAL(Z_OBJCE_P(ZEND_THIS)->name)); RETURN_THROWS(); } @@ -2672,6 +2673,7 @@ SPL_METHOD(CachingIterator, offsetSet) SPL_FETCH_AND_CHECK_DUAL_IT(intern, ZEND_THIS); if (!(intern->u.caching.flags & CIT_FULL_CACHE)) { + // Todo convert to standard exception zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "%s does not use a full cache (see CachingIterator::__construct)", ZSTR_VAL(Z_OBJCE_P(ZEND_THIS)->name)); RETURN_THROWS(); } @@ -2696,6 +2698,7 @@ SPL_METHOD(CachingIterator, offsetGet) SPL_FETCH_AND_CHECK_DUAL_IT(intern, ZEND_THIS); if (!(intern->u.caching.flags & CIT_FULL_CACHE)) { + // Todo convert to standard exception zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "%s does not use a full cache (see CachingIterator::__construct)", ZSTR_VAL(Z_OBJCE_P(ZEND_THIS)->name)); RETURN_THROWS(); } @@ -2723,6 +2726,7 @@ SPL_METHOD(CachingIterator, offsetUnset) } if (!(intern->u.caching.flags & CIT_FULL_CACHE)) { + // Todo convert to standard exception zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "%s does not use a full cache (see CachingIterator::__construct)", ZSTR_VAL(Z_OBJCE_P(ZEND_THIS)->name)); RETURN_THROWS(); } @@ -2745,6 +2749,7 @@ SPL_METHOD(CachingIterator, offsetExists) SPL_FETCH_AND_CHECK_DUAL_IT(intern, ZEND_THIS); if (!(intern->u.caching.flags & CIT_FULL_CACHE)) { + // Todo convert to standard exception zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "%s does not use a full cache (see CachingIterator::__construct)", ZSTR_VAL(Z_OBJCE_P(ZEND_THIS)->name)); RETURN_THROWS(); } @@ -2766,6 +2771,7 @@ SPL_METHOD(CachingIterator, getCache) SPL_FETCH_AND_CHECK_DUAL_IT(intern, ZEND_THIS); if (!(intern->u.caching.flags & CIT_FULL_CACHE)) { + // Todo convert to standard exception zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "%s does not use a full cache (see CachingIterator::__construct)", ZSTR_VAL(Z_OBJCE_P(ZEND_THIS)->name)); RETURN_THROWS(); } @@ -2804,15 +2810,15 @@ SPL_METHOD(CachingIterator, setFlags) SPL_FETCH_AND_CHECK_DUAL_IT(intern, ZEND_THIS); if (spl_cit_check_flags(flags) != SUCCESS) { - zend_throw_exception(spl_ce_InvalidArgumentException , "Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER", 0); + zend_argument_value_error(1, "must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER"); RETURN_THROWS(); } if ((intern->u.caching.flags & CIT_CALL_TOSTRING) != 0 && (flags & CIT_CALL_TOSTRING) == 0) { - zend_throw_exception(spl_ce_InvalidArgumentException, "Unsetting flag CALL_TO_STRING is not possible", 0); + zend_argument_value_error(1, "cannot unset flag CALL_TO_STRING", 0); RETURN_THROWS(); } if ((intern->u.caching.flags & CIT_TOSTRING_USE_INNER) != 0 && (flags & CIT_TOSTRING_USE_INNER) == 0) { - zend_throw_exception(spl_ce_InvalidArgumentException, "Unsetting flag TOSTRING_USE_INNER is not possible", 0); + zend_argument_value_error(1, "cannot unset flag TOSTRING_USE_INNER", 0); RETURN_THROWS(); } if ((flags & CIT_FULL_CACHE) != 0 && (intern->u.caching.flags & CIT_FULL_CACHE) == 0) { @@ -2836,6 +2842,7 @@ SPL_METHOD(CachingIterator, count) SPL_FETCH_AND_CHECK_DUAL_IT(intern, ZEND_THIS); if (!(intern->u.caching.flags & CIT_FULL_CACHE)) { + // Todo convert to standard exception zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "%s does not use a full cache (see CachingIterator::__construct)", ZSTR_VAL(Z_OBJCE_P(ZEND_THIS)->name)); RETURN_THROWS(); } @@ -3090,7 +3097,7 @@ SPL_METHOD(EmptyIterator, key) RETURN_THROWS(); } - zend_throw_exception(spl_ce_BadMethodCallException, "Accessing the key of an EmptyIterator", 0); + zend_throw_error(NULL, "Accessing the key of an EmptyIterator"); } /* }}} */ /* {{{ proto void EmptyIterator::current() @@ -3101,7 +3108,7 @@ SPL_METHOD(EmptyIterator, current) RETURN_THROWS(); } - zend_throw_exception(spl_ce_BadMethodCallException, "Accessing the value of an EmptyIterator", 0); + zend_throw_error(NULL, "Accessing the value of an EmptyIterator"); } /* }}} */ /* {{{ proto void EmptyIterator::next() diff --git a/ext/spl/spl_observer.c b/ext/spl/spl_observer.c index 05f529e0d7f76..c261ced22b740 100644 --- a/ext/spl/spl_observer.c +++ b/ext/spl/spl_observer.c @@ -109,7 +109,7 @@ static int spl_object_storage_get_hash(zend_hash_key *key, spl_SplObjectStorage key->key = Z_STR(rv); return SUCCESS; } else { - zend_throw_exception(spl_ce_RuntimeException, "Hash needs to be a string", 0); + zend_type_error("Hash needs to be a string"); zval_ptr_dtor(&rv); return FAILURE; @@ -439,6 +439,7 @@ SPL_METHOD(SplObjectStorage, offsetGet) spl_object_storage_free_hash(intern, &key); if (!element) { + /* Should be converted? */ zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "Object not found"); } else { zval *value = &element->inf; @@ -891,15 +892,14 @@ SPL_METHOD(SplObjectStorage, __unserialize) storage_zv = zend_hash_index_find(data, 0); members_zv = zend_hash_index_find(data, 1); - if (!storage_zv || !members_zv || - Z_TYPE_P(storage_zv) != IS_ARRAY || Z_TYPE_P(members_zv) != IS_ARRAY) { - zend_throw_exception(spl_ce_UnexpectedValueException, - "Incomplete or ill-typed serialization data", 0); + if (!storage_zv || !members_zv || Z_TYPE_P(storage_zv) != IS_ARRAY || + Z_TYPE_P(members_zv) != IS_ARRAY) { + zend_throw_error(NULL, "Incomplete or ill-typed serialization data"); RETURN_THROWS(); } if (zend_hash_num_elements(Z_ARRVAL_P(storage_zv)) % 2 != 0) { - zend_throw_exception(spl_ce_UnexpectedValueException, "Odd number of elements", 0); + zend_value_error("Odd number of elements"); RETURN_THROWS(); } @@ -907,7 +907,7 @@ SPL_METHOD(SplObjectStorage, __unserialize) ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(storage_zv), val) { if (key) { if (Z_TYPE_P(key) != IS_OBJECT) { - zend_throw_exception(spl_ce_UnexpectedValueException, "Non-object key", 0); + zend_type_error("Key must be an object"); RETURN_THROWS(); } @@ -1033,7 +1033,7 @@ SPL_METHOD(MultipleIterator, attachIterator) spl_SplObjectStorageElement *element; if (Z_TYPE_P(info) != IS_LONG && Z_TYPE_P(info) != IS_STRING) { - zend_throw_exception(spl_ce_InvalidArgumentException, "Info must be NULL, integer or string", 0); + zend_argument_type_error(2, "must be int|string|null, %s given", zend_zval_type_name(info)); RETURN_THROWS(); } @@ -1202,14 +1202,14 @@ static void spl_multiple_iterator_get_all(spl_SplObjectStorage *intern, int get_ zend_call_method_with_0_params(Z_OBJ_P(it), Z_OBJCE_P(it), &Z_OBJCE_P(it)->iterator_funcs_ptr->zf_key, "key", &retval); } if (Z_ISUNDEF(retval)) { - zend_throw_exception(spl_ce_RuntimeException, "Failed to call sub iterator method", 0); + zend_throw_error(NULL, "Failed to call sub iterator method"); return; } } else if (intern->flags & MIT_NEED_ALL) { if (SPL_MULTIPLE_ITERATOR_GET_ALL_CURRENT == get_type) { - zend_throw_exception(spl_ce_RuntimeException, "Called current() with non valid sub iterator", 0); + zend_throw_error(NULL, "Called current() with non valid sub iterator"); } else { - zend_throw_exception(spl_ce_RuntimeException, "Called key() with non valid sub iterator", 0); + zend_throw_error(NULL, "Called key() with non valid sub iterator"); } return; } else { @@ -1226,7 +1226,7 @@ static void spl_multiple_iterator_get_all(spl_SplObjectStorage *intern, int get_ break; default: zval_ptr_dtor(&retval); - zend_throw_exception(spl_ce_InvalidArgumentException, "Sub-Iterator is associated with NULL", 0); + zend_throw_error(NULL, "Sub-Iterator is associated with NULL"); return; } } else { diff --git a/ext/spl/tests/ArrayObject_exchange_array_during_sorting.phpt b/ext/spl/tests/ArrayObject_exchange_array_during_sorting.phpt index 225d42c1ed030..a95039023b794 100644 --- a/ext/spl/tests/ArrayObject_exchange_array_during_sorting.phpt +++ b/ext/spl/tests/ArrayObject_exchange_array_during_sorting.phpt @@ -7,15 +7,19 @@ $ao = new ArrayObject([1, 2, 3]); $i = 0; $ao->uasort(function($a, $b) use ($ao, &$i) { if ($i++ == 0) { - $ao->exchangeArray([4, 5, 6]); + try { + $ao->exchangeArray([4, 5, 6]); + } catch (\Error $e) { + echo $e->getMessage() .\PHP_EOL; + } var_dump($ao); } return $a <=> $b; }); ?> ---EXPECTF-- -Warning: Modification of ArrayObject during sorting is prohibited in %s on line %d +--EXPECT-- +Modification of ArrayObject during sorting is prohibited object(ArrayObject)#1 (1) { ["storage":"ArrayObject":private]=> array(3) { diff --git a/ext/spl/tests/ArrayObject_illegal_offset_leak.phpt b/ext/spl/tests/ArrayObject_illegal_offset_leak.phpt index 42c649db9f615..0a8877a98bcdf 100644 --- a/ext/spl/tests/ArrayObject_illegal_offset_leak.phpt +++ b/ext/spl/tests/ArrayObject_illegal_offset_leak.phpt @@ -4,8 +4,12 @@ Assignments to illegal ArrayObject offsets shouldn't leak getMessage() . \PHP_EOL; +} ?> ---EXPECTF-- -Warning: Illegal offset type in %s on line %d +--EXPECT-- +Offsets must be int|string, array given diff --git a/ext/spl/tests/ArrayObject_overloaded_object_incompatible.phpt b/ext/spl/tests/ArrayObject_overloaded_object_incompatible.phpt index 8c1121b8d01ad..c7de6756ff064 100644 --- a/ext/spl/tests/ArrayObject_overloaded_object_incompatible.phpt +++ b/ext/spl/tests/ArrayObject_overloaded_object_incompatible.phpt @@ -6,14 +6,14 @@ Objects with overloaded get_properties are incompatible with ArrayObject $ao = new ArrayObject([1, 2, 3]); try { $ao->exchangeArray(new SplFixedArray); -} catch (Exception $e) { +} catch (\TypeError $e) { echo $e->getMessage(), "\n"; } var_dump($ao); ?> --EXPECT-- -Overloaded object of type SplFixedArray is not compatible with ArrayObject +ArrayObject::exchangeArray(): Argument #1 ($input) must be compatible with ArrayObject object(ArrayObject)#1 (1) { ["storage":"ArrayObject":private]=> array(3) { diff --git a/ext/spl/tests/DirectoryIterator_empty_constructor.phpt b/ext/spl/tests/DirectoryIterator_empty_constructor.phpt index cf96425892603..3887dc317170a 100644 --- a/ext/spl/tests/DirectoryIterator_empty_constructor.phpt +++ b/ext/spl/tests/DirectoryIterator_empty_constructor.phpt @@ -5,11 +5,13 @@ Havard Eide #PHPTestFest2009 Norway 2009-06-09 \o/ --FILE-- getMessage() . PHP_EOL; +} + ?> ---EXPECTF-- -Fatal error: Uncaught RuntimeException: Directory name must not be empty. in %s:%d -Stack trace: -#0 %s(%d): DirectoryIterator->__construct('') -#1 {main} - thrown in %s on line %d +--EXPECT-- +DirectoryIterator::__construct(): Argument #1 ($path) cannot be empty diff --git a/ext/spl/tests/SPLDoublyLinkedList_iterate_by_reference.phpt b/ext/spl/tests/SPLDoublyLinkedList_iterate_by_reference.phpt index 8c3aad3ef7dba..769136c4064fa 100644 --- a/ext/spl/tests/SPLDoublyLinkedList_iterate_by_reference.phpt +++ b/ext/spl/tests/SPLDoublyLinkedList_iterate_by_reference.phpt @@ -17,7 +17,7 @@ try { $value *= $value; echo $value, PHP_EOL; } -} catch (Exception $e) { +} catch (\Error $e) { echo $e->getMessage(), PHP_EOL; } diff --git a/ext/spl/tests/SplArray_fromArray.phpt b/ext/spl/tests/SplArray_fromArray.phpt index 143d2755a81de..0b2bec0ebe0d9 100644 --- a/ext/spl/tests/SplArray_fromArray.phpt +++ b/ext/spl/tests/SplArray_fromArray.phpt @@ -9,9 +9,9 @@ $splArray = new SplFixedArray(); try { $splArray->fromArray($array); -} catch (Exception $e) { +} catch (Error $e) { echo $e->getMessage(); } ?> --EXPECT-- -integer overflow detected +Integer overflow detected diff --git a/ext/spl/tests/SplDoublyLinkedList_add_invalid_offset.phpt b/ext/spl/tests/SplDoublyLinkedList_add_invalid_offset.phpt index 401d8ae1b3a7a..212eeb650031d 100644 --- a/ext/spl/tests/SplDoublyLinkedList_add_invalid_offset.phpt +++ b/ext/spl/tests/SplDoublyLinkedList_add_invalid_offset.phpt @@ -3,11 +3,11 @@ Check that SplDoublyLinkedList::add throws an exception with an invalid offset a --FILE-- add(12,'Offset 12 should not exist')); -} catch (OutOfRangeException $e) { - echo "Exception: ".$e->getMessage()."\n"; + $dll = new SplDoublyLinkedList(); + var_dump($dll->add(12,'Offset 12 should not exist')); +} catch (\ValueError $e) { + echo $e->getMessage()."\n"; } ?> --EXPECT-- -Exception: Offset invalid or out of range +SplDoublyLinkedList::add(): Argument #1 ($index) is out of range diff --git a/ext/spl/tests/SplDoublyLinkedList_add_null_offset.phpt b/ext/spl/tests/SplDoublyLinkedList_add_null_offset.phpt index f8c58d9c705ba..f3552ba0d9d05 100644 --- a/ext/spl/tests/SplDoublyLinkedList_add_null_offset.phpt +++ b/ext/spl/tests/SplDoublyLinkedList_add_null_offset.phpt @@ -3,11 +3,11 @@ Check that SplDoublyLinkedList::add throws an exception with an invalid offset a --FILE-- add(NULL,2)); -} catch (OutOfRangeException $e) { - echo "Exception: ".$e->getMessage()."\n"; + $dll = new SplDoublyLinkedList(); + var_dump($dll->add(NULL,2)); +} catch (\ValueError $e) { + echo $e->getMessage()."\n"; } ?> --EXPECT-- -Exception: Offset invalid or out of range +SplDoublyLinkedList::add(): Argument #1 ($index) is out of range diff --git a/ext/spl/tests/SplDoublyLinkedList_offsetGet_param_array.phpt b/ext/spl/tests/SplDoublyLinkedList_offsetGet_param_array.phpt index b6debb109bd16..5887f2b296831 100644 --- a/ext/spl/tests/SplDoublyLinkedList_offsetGet_param_array.phpt +++ b/ext/spl/tests/SplDoublyLinkedList_offsetGet_param_array.phpt @@ -7,12 +7,12 @@ PHPNW Test Fest 2009 - Jordan Hatch $array = new SplDoublyLinkedList( ); -$get = $array->offsetGet( array( 'fail' ) ); +try { + $array->offsetGet( array( 'fail' ) ); +} catch(\ValueError $e) { + echo $e->getMessage(); +} ?> ---EXPECTF-- -Fatal error: Uncaught OutOfRangeException: Offset invalid or out of range in %s -Stack trace: -#0 %s -#1 {main} - thrown in %s on line %d +--EXPECT-- +SplDoublyLinkedList::offsetGet(): Argument #1 ($index) is out of range diff --git a/ext/spl/tests/SplDoublyLinkedList_offsetGet_param_string.phpt b/ext/spl/tests/SplDoublyLinkedList_offsetGet_param_string.phpt index 43ce18c5c5ba5..c2d80fc680ba0 100644 --- a/ext/spl/tests/SplDoublyLinkedList_offsetGet_param_string.phpt +++ b/ext/spl/tests/SplDoublyLinkedList_offsetGet_param_string.phpt @@ -7,12 +7,12 @@ PHPNW Test Fest 2009 - Jordan Hatch $array = new SplDoublyLinkedList( ); -$get = $array->offsetGet( 'fail' ); +try { + $array->offsetGet( 'fail' ); +} catch(\ValueError $e) { + echo $e->getMessage(); +} ?> ---EXPECTF-- -Fatal error: Uncaught OutOfRangeException: Offset invalid or out of range in %s -Stack trace: -#0 %s -#1 {main} - thrown in %s on line %d +--EXPECT-- +SplDoublyLinkedList::offsetGet(): Argument #1 ($index) is out of range diff --git a/ext/spl/tests/SplDoublyLinkedList_offsetUnset_greater_than_elements.phpt b/ext/spl/tests/SplDoublyLinkedList_offsetUnset_greater_than_elements.phpt index 2512e23e78277..d711e9acb92a8 100644 --- a/ext/spl/tests/SplDoublyLinkedList_offsetUnset_greater_than_elements.phpt +++ b/ext/spl/tests/SplDoublyLinkedList_offsetUnset_greater_than_elements.phpt @@ -11,15 +11,12 @@ $ll->push('2'); $ll->push('3'); try { - -$ll->offsetUnset($ll->count() + 1); - -var_dump($ll); - -} catch(Exception $e) { -echo $e->getMessage(); + $ll->offsetUnset($ll->count() + 1); + var_dump($ll); +} catch(\ValueError $e) { + echo $e->getMessage(); } ?> --EXPECT-- -Offset out of range +SplDoublyLinkedList::offsetUnset(): Argument #1 ($index) is out of range diff --git a/ext/spl/tests/SplDoublyLinkedList_offsetUnset_negative-parameter.phpt b/ext/spl/tests/SplDoublyLinkedList_offsetUnset_negative-parameter.phpt index 364eb5ca79a6c..609eebdfb6b27 100644 --- a/ext/spl/tests/SplDoublyLinkedList_offsetUnset_negative-parameter.phpt +++ b/ext/spl/tests/SplDoublyLinkedList_offsetUnset_negative-parameter.phpt @@ -12,12 +12,11 @@ PHPNW Testfest 2009 - Paul Court ( g@rgoyle.com ) $dll->push(2); $dll->push(3); - try { - $dll->offsetUnset(-1); - } - catch (Exception $e) { - echo $e->getMessage() . "\n"; - } + try { + $dll->offsetUnset(-1); + } catch (\ValueError $e) { + echo $e->getMessage() . "\n"; + } ?> --EXPECT-- -Offset out of range +SplDoublyLinkedList::offsetUnset(): Argument #1 ($index) is out of range diff --git a/ext/spl/tests/SplDoublyLinkedList_offsetUnset_parameter-larger-num-elements.phpt b/ext/spl/tests/SplDoublyLinkedList_offsetUnset_parameter-larger-num-elements.phpt index 5ba7b27e56bf9..dc685f7664330 100644 --- a/ext/spl/tests/SplDoublyLinkedList_offsetUnset_parameter-larger-num-elements.phpt +++ b/ext/spl/tests/SplDoublyLinkedList_offsetUnset_parameter-larger-num-elements.phpt @@ -12,12 +12,11 @@ PHPNW Testfest 2009 - Paul Court ( g@rgoyle.com ) $dll->push(2); $dll->push(3); - try { - $dll->offsetUnset(3); - } - catch (Exception $e) { - echo $e->getMessage() . "\n"; - } + try { + $dll->offsetUnset(3); + } catch (\ValueError $e) { + echo $e->getMessage() . "\n"; + } ?> --EXPECT-- -Offset out of range +SplDoublyLinkedList::offsetUnset(): Argument #1 ($index) is out of range diff --git a/ext/spl/tests/SplFileObject_fgetcsv_delimiter_error.phpt b/ext/spl/tests/SplFileObject_fgetcsv_delimiter_error.phpt index 2db10f989a09f..a64aad9eab3e4 100644 --- a/ext/spl/tests/SplFileObject_fgetcsv_delimiter_error.phpt +++ b/ext/spl/tests/SplFileObject_fgetcsv_delimiter_error.phpt @@ -12,12 +12,15 @@ fputcsv($fp, array( fclose($fp); $fo = new SplFileObject('SplFileObject__fgetcsv3.csv'); -var_dump($fo->fgetcsv('invalid')); +try { + var_dump($fo->fgetcsv('invalid')); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} ?> --CLEAN-- ---EXPECTF-- -Warning: SplFileObject::fgetcsv(): delimiter must be a character in %s on line %d -bool(false) +--EXPECT-- +SplFileObject::fgetcsv(): Argument #1 ($delimiter) must be a character diff --git a/ext/spl/tests/SplFileObject_fgetcsv_enclosure_error.phpt b/ext/spl/tests/SplFileObject_fgetcsv_enclosure_error.phpt index 6dd0a593c5b38..8ef5dac3053b8 100644 --- a/ext/spl/tests/SplFileObject_fgetcsv_enclosure_error.phpt +++ b/ext/spl/tests/SplFileObject_fgetcsv_enclosure_error.phpt @@ -12,12 +12,15 @@ fputcsv($fp, array( fclose($fp); $fo = new SplFileObject('SplFileObject__fgetcsv5.csv'); -var_dump($fo->fgetcsv(',', 'invalid')); +try { + var_dump($fo->fgetcsv(',', 'invalid')); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} ?> --CLEAN-- ---EXPECTF-- -Warning: SplFileObject::fgetcsv(): enclosure must be a character in %s on line %d -bool(false) +--EXPECT-- +SplFileObject::fgetcsv(): Argument #2 ($enclosure) must be a character diff --git a/ext/spl/tests/SplFileObject_fgetcsv_escape_error.phpt b/ext/spl/tests/SplFileObject_fgetcsv_escape_error.phpt index 4873341e5a2b9..542796f00b604 100644 --- a/ext/spl/tests/SplFileObject_fgetcsv_escape_error.phpt +++ b/ext/spl/tests/SplFileObject_fgetcsv_escape_error.phpt @@ -7,12 +7,15 @@ fwrite($fp, '"aaa","b""bb","ccc"'); fclose($fp); $fo = new SplFileObject('SplFileObject__fgetcsv8.csv'); -var_dump($fo->fgetcsv(',', '"', 'invalid')); +try { + var_dump($fo->fgetcsv(',', '"', 'invalid')); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} ?> --CLEAN-- ---EXPECTF-- -Warning: SplFileObject::fgetcsv(): escape must be empty or a single character in %s on line %d -bool(false) +--EXPECT-- +SplFileObject::fgetcsv(): Argument #3 ($escape) must be empty or a single character diff --git a/ext/spl/tests/SplFileObject_fputcsv_variation13.phpt b/ext/spl/tests/SplFileObject_fputcsv_variation13.phpt index a4c24510216b8..8ce4f490dda7d 100644 --- a/ext/spl/tests/SplFileObject_fputcsv_variation13.phpt +++ b/ext/spl/tests/SplFileObject_fputcsv_variation13.phpt @@ -10,20 +10,20 @@ echo "*** Testing fputcsv() : with default enclosure & delimiter of two chars ** $fo = new SplFileObject(__DIR__ . '/SplFileObject_fputcsv_variation13.csv', 'w'); -var_dump($fo->fputcsv(array('water', 'fruit'), ',,', '"')); +try { + var_dump($fo->fputcsv(array('water', 'fruit'), ',,', '"')); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} unset($fo); -echo "Done\n"; ?> --CLEAN-- ---EXPECTF-- +--EXPECT-- *** Testing fputcsv() : with default enclosure & delimiter of two chars *** - -Warning: SplFileObject::fputcsv(): delimiter must be a character in %s on line %d -bool(false) -Done +SplFileObject::fputcsv(): Argument #2 ($delimiter) must be a character diff --git a/ext/spl/tests/SplFileObject_fputcsv_variation14.phpt b/ext/spl/tests/SplFileObject_fputcsv_variation14.phpt index a659da92af46e..18f9b77e94139 100644 --- a/ext/spl/tests/SplFileObject_fputcsv_variation14.phpt +++ b/ext/spl/tests/SplFileObject_fputcsv_variation14.phpt @@ -10,20 +10,20 @@ echo "*** Testing fputcsv() : with enclosure & delimiter of two chars and file o $fo = new SplFileObject(__DIR__ . '/SplFileObject_fputcsv_variation14.csv', 'w'); -var_dump($fo->fputcsv(array('water', 'fruit'), ',,', '""')); +try { + var_dump($fo->fputcsv(array('water', 'fruit'), ',,', '""')); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} unset($fo); -echo "Done\n"; ?> --CLEAN-- ---EXPECTF-- +--EXPECT-- *** Testing fputcsv() : with enclosure & delimiter of two chars and file opened in read mode *** - -Warning: SplFileObject::fputcsv(): enclosure must be a character in %s on line %d -bool(false) -Done +SplFileObject::fputcsv(): Argument #3 ($enclosure) must be a character diff --git a/ext/spl/tests/SplFileObject_seek_error_001.phpt b/ext/spl/tests/SplFileObject_seek_error_001.phpt index acebb66f41569..2b182e06005df 100644 --- a/ext/spl/tests/SplFileObject_seek_error_001.phpt +++ b/ext/spl/tests/SplFileObject_seek_error_001.phpt @@ -4,10 +4,10 @@ SplFileObject::seek function - test parameters seek(-1); -} catch (LogicException $e) { - echo($e->getMessage()); + $obj->seek(-1); +} catch (\ValueError $e) { + echo($e->getMessage()); } ?> --EXPECTF-- -Can't seek file %s to negative line -1 +Can't seek file %s to negative line diff --git a/ext/spl/tests/SplFileObject_setCsvControl_error001.phpt b/ext/spl/tests/SplFileObject_setCsvControl_error001.phpt index 296c4a1aa0c44..d2a3d268fec43 100644 --- a/ext/spl/tests/SplFileObject_setCsvControl_error001.phpt +++ b/ext/spl/tests/SplFileObject_setCsvControl_error001.phpt @@ -13,11 +13,15 @@ CDATA ); $s = new SplFileObject('csv_control_data_error001.csv'); $s->setFlags(SplFileObject::READ_CSV); -$s->setCsvControl('||'); +try { + $s->setCsvControl('||'); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} ?> --CLEAN-- ---EXPECTF-- -Warning: SplFileObject::setCsvControl(): delimiter must be a character in %s on line %d +--EXPECT-- +SplFileObject::setCsvControl(): Argument #1 ($delimiter) must be a character diff --git a/ext/spl/tests/SplFileObject_setCsvControl_error002.phpt b/ext/spl/tests/SplFileObject_setCsvControl_error002.phpt index 885d600225256..1c878f8254269 100644 --- a/ext/spl/tests/SplFileObject_setCsvControl_error002.phpt +++ b/ext/spl/tests/SplFileObject_setCsvControl_error002.phpt @@ -13,11 +13,15 @@ CDATA ); $s = new SplFileObject('csv_control_data_error002.csv'); $s->setFlags(SplFileObject::READ_CSV); -$s->setCsvControl('|', 'two'); +try { + $s->setCsvControl('|', 'two'); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} ?> --CLEAN-- ---EXPECTF-- -Warning: SplFileObject::setCsvControl(): enclosure must be a character in %s on line %d +--EXPECT-- +SplFileObject::setCsvControl(): Argument #2 ($enclosure) must be a character diff --git a/ext/spl/tests/SplFileObject_setCsvControl_error003.phpt b/ext/spl/tests/SplFileObject_setCsvControl_error003.phpt index 9e885cbbe3dce..b767bfcc69369 100644 --- a/ext/spl/tests/SplFileObject_setCsvControl_error003.phpt +++ b/ext/spl/tests/SplFileObject_setCsvControl_error003.phpt @@ -15,11 +15,15 @@ CDATA ); $s = new SplFileObject('csv_control_data_error003.csv'); $s->setFlags(SplFileObject::READ_CSV); -$s->setCsvControl('|', '\'', 'three'); +try { + $s->setCsvControl('|', '\'', 'three'); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} ?> --CLEAN-- ---EXPECTF-- -Warning: SplFileObject::setCsvControl(): escape must be empty or a single character in %s on line %d +--EXPECT-- +SplFileObject::setCsvControl(): Argument #3 ($escape) must be empty or a single character diff --git a/ext/spl/tests/SplFixedArray_setSize_param_null.phpt b/ext/spl/tests/SplFixedArray_setSize_param_null.phpt index ddb37be9f0352..5039fcc84cc66 100644 --- a/ext/spl/tests/SplFixedArray_setSize_param_null.phpt +++ b/ext/spl/tests/SplFixedArray_setSize_param_null.phpt @@ -7,6 +7,7 @@ PHPNW Testfest 2009 - Adrian Hardy $fixed_array = new SplFixedArray(2); $fixed_array->setSize(null); var_dump($fixed_array); + ?> --EXPECT-- object(SplFixedArray)#1 (0) { diff --git a/ext/spl/tests/SplObjectStorage_getHash.phpt b/ext/spl/tests/SplObjectStorage_getHash.phpt index 85cdcb4e7a014..f02b3eef5211e 100644 --- a/ext/spl/tests/SplObjectStorage_getHash.phpt +++ b/ext/spl/tests/SplObjectStorage_getHash.phpt @@ -6,7 +6,7 @@ $s = new SplObjectStorage(); $o1 = new Stdclass; $o2 = new Stdclass; $s[$o1] = "some_value\n"; -echo $s->offsetGet($o1); +var_dump($s->offsetGet($o1)); class MySplObjectStorage extends SplObjectStorage { public function getHash($obj) { @@ -17,8 +17,8 @@ class MySplObjectStorage extends SplObjectStorage { try { $s1 = new MySplObjectStorage; $s1[$o1] = "foo"; -} catch(Exception $e) { - echo "caught\n"; +} catch (\TypeError $e) { + echo $e->getMessage() . PHP_EOL; } class MySplObjectStorage2 extends SplObjectStorage { @@ -31,8 +31,8 @@ class MySplObjectStorage2 extends SplObjectStorage { try { $s2 = new MySplObjectStorage2; $s2[$o2] = "foo"; -} catch(Exception $e) { - echo "caught\n"; +} catch (\Exception $e) { + echo $e->getMessage() . PHP_EOL; } class MySplObjectStorage3 extends SplObjectStorage { @@ -49,10 +49,11 @@ $s3[$o2] = $o2; var_dump($s3[$o1] === $s3[$o2]); ?> ---EXPECT-- -some_value -caught -caught -object(stdClass)#2 (0) { +--EXPECTF-- +string(11) "some_value +" +Hash needs to be a string +foo +object(stdClass)#%d (0) { } bool(true) diff --git a/ext/spl/tests/SplPriorityQueue_setExtractFlags_zero.phpt b/ext/spl/tests/SplPriorityQueue_setExtractFlags_zero.phpt index cf2d339914907..303b62579a852 100644 --- a/ext/spl/tests/SplPriorityQueue_setExtractFlags_zero.phpt +++ b/ext/spl/tests/SplPriorityQueue_setExtractFlags_zero.phpt @@ -4,12 +4,12 @@ Setting SplPriorityQueue extract flags to zero generates an exception setExtractFlags(0); +try { + $queue->setExtractFlags(0); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} ?> ---EXPECTF-- -Fatal error: Uncaught RuntimeException: Must specify at least one extract flag in %s:%d -Stack trace: -#0 %s(%d): SplPriorityQueue->setExtractFlags(0) -#1 {main} - thrown in %s on line %d +--EXPECT-- +SplPriorityQueue::setExtractFlags(): Argument #1 ($flags) must specify at least one extract flag diff --git a/ext/spl/tests/arrayObject_exchangeArray_basic3.phpt b/ext/spl/tests/arrayObject_exchangeArray_basic3.phpt index d05a635500f2d..53fac70ece197 100644 --- a/ext/spl/tests/arrayObject_exchangeArray_basic3.phpt +++ b/ext/spl/tests/arrayObject_exchangeArray_basic3.phpt @@ -40,10 +40,10 @@ unset($original, $ao, $swapIn, $copy); $original = new C; $ao = new ArrayObject($original); try { - $copy = $ao->exchangeArray(null); - $copy['addedToCopy'] = 'added To Copy'; -} catch (Exception $e) { - echo "Exception:" . $e->getMessage() . "\n"; + $copy = $ao->exchangeArray(null); + $copy['addedToCopy'] = 'added To Copy'; +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; } $original->addedToOriginal = 'added To Original'; var_dump($ao, $original, $copy); @@ -103,7 +103,7 @@ NULL --> exchangeArray() with bad arg type: -Exception:Passed variable is not an array or object +ArrayObject::exchangeArray(): Argument #1 ($input) must be array|object, null given Warning: Undefined variable $copy in %s on line %d object(ArrayObject)#3 (1) { diff --git a/ext/spl/tests/arrayObject_uasort_error1.phpt b/ext/spl/tests/arrayObject_uasort_error1.phpt index 5dc63373ef636..439f5920ca2cb 100644 --- a/ext/spl/tests/arrayObject_uasort_error1.phpt +++ b/ext/spl/tests/arrayObject_uasort_error1.phpt @@ -12,15 +12,15 @@ Test ArrayObject::uasort() function : wrong arg count $ao = new ArrayObject(); try { - $ao->uasort(); -} catch (BadMethodCallException $e) { - echo $e->getMessage() . "\n"; + $ao->uasort(); +} catch (\ArgumentCountError $e) { + echo $e->getMessage() . "\n"; } try { - $ao->uasort(1,2); -} catch (BadMethodCallException $e) { - echo $e->getMessage() . "\n"; + $ao->uasort(1,2); +} catch (\ArgumentCountError $e) { + echo $e->getMessage() . "\n"; } ?> --EXPECT-- diff --git a/ext/spl/tests/arrayObject_uksort_error1.phpt b/ext/spl/tests/arrayObject_uksort_error1.phpt index e2bbf9968cfa2..ec6ef37f493e2 100644 --- a/ext/spl/tests/arrayObject_uksort_error1.phpt +++ b/ext/spl/tests/arrayObject_uksort_error1.phpt @@ -12,15 +12,15 @@ Test ArrayObject::uksort() function : wrong arg count $ao = new ArrayObject(); try { - $ao->uksort(); -} catch (BadMethodCallException $e) { - echo $e->getMessage() . "\n"; + $ao->uksort(); +} catch (\ArgumentCountError $e) { + echo $e->getMessage() . "\n"; } try { - $ao->uksort(1,2); -} catch (BadMethodCallException $e) { - echo $e->getMessage() . "\n"; + $ao->uksort(1,2); +} catch (\ArgumentCountError $e) { + echo $e->getMessage() . "\n"; } ?> --EXPECT-- diff --git a/ext/spl/tests/array_014.phpt b/ext/spl/tests/array_014.phpt index 37ed9abad507c..e73ba159a2297 100644 --- a/ext/spl/tests/array_014.phpt +++ b/ext/spl/tests/array_014.phpt @@ -9,24 +9,20 @@ $it->seek(5); var_dump($it->current()); $it->seek(4); var_dump($it->current()); -try -{ - $it->seek(-1); - var_dump($it->current()); -} -catch(Exception $e) -{ - echo $e->getMessage() . "\n"; -} -try -{ - $it->seek(12); - var_dump($it->current()); +try { + $it->seek(-1); + var_dump($it->current()); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; } -catch(Exception $e) -{ - echo $e->getMessage() . "\n"; + + +try { + $it->seek(12); + var_dump($it->current()); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; } $pos = 0; @@ -41,8 +37,8 @@ foreach($it as $v) int(11) int(5) int(4) -Seek position -1 is out of range -Seek position 12 is out of range +ArrayIterator::seek(): Argument #1 ($position) position -1 is out of range +ArrayIterator::seek(): Argument #1 ($position) position 12 is out of range int(0) int(1) int(2) diff --git a/ext/spl/tests/array_019.phpt b/ext/spl/tests/array_019.phpt index 2a86e70589381..9cabf0b3c449e 100644 --- a/ext/spl/tests/array_019.phpt +++ b/ext/spl/tests/array_019.phpt @@ -16,17 +16,16 @@ class ArrayIteratorEx extends ArrayIterator } $ar = new ArrayIteratorEx(array(4)); foreach($ar as $v) var_dump($v); -$ar = new ArrayIteratorEx(array(5)); foreach($ar as &$v) var_dump($v); +try { + $ar = new ArrayIteratorEx(array(5)); foreach($ar as &$v) var_dump($v); +} catch (\Error $e) { + echo $e->getMessage() . \PHP_EOL; +} ?> -===DONE=== ---EXPECTF-- +--EXPECT-- int(1) int(2) int(3) int(4) - -Fatal error: Uncaught RuntimeException: An iterator cannot be used with foreach by reference in %s:%d -Stack trace: -#0 {main} - thrown in %s on line %d +An iterator cannot be used with foreach by reference diff --git a/ext/spl/tests/bug41828.phpt b/ext/spl/tests/bug41828.phpt index 6053e0e4468be..d25e87724c41a 100644 --- a/ext/spl/tests/bug41828.phpt +++ b/ext/spl/tests/bug41828.phpt @@ -12,10 +12,12 @@ class foo extends RecursiveIteratorIterator { } $foo = new foo("This is bar"); -echo $foo->bar(); +try { + echo $foo->bar(); +} catch (Error $e) { + echo $e->getMessage() . \PHP_EOL; +} ?> -==DONE== - ---EXPECTF-- -Fatal error: main(): The foo instance wasn't initialized properly in %s on line %d +--EXPECT-- +The foo instance wasn't initialized properly diff --git a/ext/spl/tests/bug46160.phpt b/ext/spl/tests/bug46160.phpt index 3e03f094d376f..e52936fe0cc46 100644 --- a/ext/spl/tests/bug46160.phpt +++ b/ext/spl/tests/bug46160.phpt @@ -2,13 +2,12 @@ Bug #46160 (SPL - Memory leak when exception is throwed in offsetSet method) --FILE-- offsetSet(0, 0); -} catch (Exception $e) { } - + $x = new splqueue; + $x->offsetSet(0, 0); +} catch (\ValueError $e) { + echo $e->getMessage()."\n"; +} ?> -DONE --EXPECT-- -DONE +SplDoublyLinkedList::offsetSet(): Argument #1 ($index) is out of range diff --git a/ext/spl/tests/bug51119.phpt b/ext/spl/tests/bug51119.phpt index aba523dc62955..ee144047a4d0b 100644 --- a/ext/spl/tests/bug51119.phpt +++ b/ext/spl/tests/bug51119.phpt @@ -20,8 +20,8 @@ try { foreach ($limitIterator as $item) { echo $item . "\n"; } -} catch (OutOfRangeException $e){ - print $e->getMessage() . "\n"; +} catch (\ValueError $e){ + echo $e->getMessage() . PHP_EOL; } ?> @@ -29,4 +29,4 @@ try { a b c -Parameter offset must be >= 0 +LimitIterator::__construct(): Argument #1 ($iterator) must be greater or equal to 0 diff --git a/ext/spl/tests/bug53362.phpt b/ext/spl/tests/bug53362.phpt index eec1f037eba0c..485161d18e99f 100644 --- a/ext/spl/tests/bug53362.phpt +++ b/ext/spl/tests/bug53362.phpt @@ -11,12 +11,24 @@ class obj extends SplFixedArray{ $obj = new obj; -$obj[]=2; -$obj[]=2; -$obj[]=2; +try { + $obj[]=2; +} catch (\Error $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + $obj[]=2; +} catch (\Error $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + $obj[]=2; +} catch (\Error $e) { + echo $e->getMessage() . \PHP_EOL; +} ?> --EXPECT-- -NULL -NULL -NULL +Dynamic allocation is forbidden +Dynamic allocation is forbidden +Dynamic allocation is forbidden diff --git a/ext/spl/tests/bug54281.phpt b/ext/spl/tests/bug54281.phpt index 5d214d9b18b3a..8711f32050975 100644 --- a/ext/spl/tests/bug54281.phpt +++ b/ext/spl/tests/bug54281.phpt @@ -8,12 +8,12 @@ class RecursiveArrayIteratorIterator extends RecursiveIteratorIterator { } $it = new RecursiveArrayIteratorIterator(new RecursiveArrayIterator(array()), 2); -foreach($it as $k=>$v) { } +try { + foreach($it as $k=>$v) { } +} catch (\Error $e) { + echo $e->getMessage() . \PHP_EOL; +} ?> ---EXPECTF-- -Fatal error: Uncaught LogicException: The object is in an invalid state as the parent constructor was not called in %s:%d -Stack trace: -#0 %s%ebug54281.php(8): RecursiveIteratorIterator->rewind() -#1 {main} - thrown in %s%ebug54281.php on line 8 +--EXPECT-- +The object is in an invalid state as the parent constructor was not called diff --git a/ext/spl/tests/bug54384.phpt b/ext/spl/tests/bug54384.phpt index 581845a43ab12..0388dce1fc5af 100644 --- a/ext/spl/tests/bug54384.phpt +++ b/ext/spl/tests/bug54384.phpt @@ -7,8 +7,8 @@ function test($f) { try { $f(); echo "ran normally (unexpected)\n\n"; - } catch (LogicException $e) { - echo "exception (expected)\n"; + } catch (\Error|\LogicException $e) { + echo get_class($e) . " (expected)\n"; } } @@ -153,18 +153,18 @@ echo $a,"\n"; } } ); --EXPECT-- -IteratorIterator... exception (expected) -FilterIterator... exception (expected) -RecursiveFilterIterator... exception (expected) -ParentIterator... exception (expected) -LimitIterator... exception (expected) -CachingIterator... exception (expected) -RecursiveCachingIterator... exception (expected) -NoRewindIterator... exception (expected) -RegexIterator... exception (expected) -RecursiveRegexIterator... exception (expected) -GlobIterator... exception (expected) -SplFileObject... exception (expected) -SplTempFileObject... exception (expected) -AppendIterator... exception (expected) -InfiniteIterator... exception (expected) +IteratorIterator... Error (expected) +FilterIterator... Error (expected) +RecursiveFilterIterator... Error (expected) +ParentIterator... Error (expected) +LimitIterator... Error (expected) +CachingIterator... Error (expected) +RecursiveCachingIterator... Error (expected) +NoRewindIterator... Error (expected) +RegexIterator... Error (expected) +RecursiveRegexIterator... Error (expected) +GlobIterator... LogicException (expected) +SplFileObject... LogicException (expected) +SplTempFileObject... LogicException (expected) +AppendIterator... Error (expected) +InfiniteIterator... Error (expected) diff --git a/ext/spl/tests/bug61828.phpt b/ext/spl/tests/bug61828.phpt index 04d435e6d6edd..721c6f9285f00 100644 --- a/ext/spl/tests/bug61828.phpt +++ b/ext/spl/tests/bug61828.phpt @@ -3,9 +3,11 @@ Bug #61828 (Memleak when calling Directory(Recursive)Iterator/Spl(Temp)FileObjec --FILE-- __construct('/tmp'); -echo "Okey"; +try { + $x->__construct('/tmp'); +} catch (\Error $e) { + echo $e->getMessage() . \PHP_EOL; +} ?> ---EXPECTF-- -Warning: DirectoryIterator::__construct(): Directory object is already initialized in %sbug61828.php on line 3 -Okey +--EXPECT-- +Directory object is already initialized diff --git a/ext/spl/tests/bug64106.phpt b/ext/spl/tests/bug64106.phpt index 26203c4e2e9a2..295236855b067 100644 --- a/ext/spl/tests/bug64106.phpt +++ b/ext/spl/tests/bug64106.phpt @@ -12,6 +12,4 @@ $array[][1] = 10; ?> --EXPECTF-- -NULL - Notice: Indirect modification of overloaded element of MyFixedArray has no effect in %s on line %d diff --git a/ext/spl/tests/bug65545.phpt b/ext/spl/tests/bug65545.phpt index bd5a7f06dbfd8..15dda2812ca3d 100644 --- a/ext/spl/tests/bug65545.phpt +++ b/ext/spl/tests/bug65545.phpt @@ -6,7 +6,12 @@ $obj = new SplFileObject(__FILE__, 'r'); $data = $obj->fread(5); var_dump($data); -$data = $obj->fread(0); + +try { + $data = $obj->fread(0); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} var_dump($data); // read more data than is available @@ -14,9 +19,8 @@ $data = $obj->fread(filesize(__FILE__) + 32); var_dump(strlen($data) === filesize(__FILE__) - 5); ?> ---EXPECTF-- +--EXPECT-- +string(5) "unserialize($GLOBALS['it']->serialize()); return TRUE; } - -$it->uksort('badsort'); ---EXPECTF-- -Warning: Modification of ArrayObject during sorting is prohibited in %sbug67539.php on line %d +try { + $it->uksort('badsort'); +} catch (\Error $e) { + echo $e->getMessage() . \PHP_EOL; +} +--EXPECT-- +Modification of ArrayObject during sorting is prohibited diff --git a/ext/spl/tests/bug70155.phpt b/ext/spl/tests/bug70155.phpt index 0aa246cc2388f..e701cd2cd971f 100644 --- a/ext/spl/tests/bug70155.phpt +++ b/ext/spl/tests/bug70155.phpt @@ -4,14 +4,13 @@ SPL: Bug #70155 Use After Free Vulnerability in unserialize() with SPLArrayObjec getMessage() . \PHP_EOL; +} + ?> ---EXPECTF-- -Fatal error: Uncaught InvalidArgumentException: Overloaded object of type DateInterval is not compatible with ArrayObject in %s -Stack trace: -%s -%s -%s -%s +--EXPECT-- +Overloaded object of type DateInterval must be compatible with ArrayObject diff --git a/ext/spl/tests/bug70561.phpt b/ext/spl/tests/bug70561.phpt index c6c229ad89d0d..dd800e9b11c62 100644 --- a/ext/spl/tests/bug70561.phpt +++ b/ext/spl/tests/bug70561.phpt @@ -13,11 +13,11 @@ while ($di->valid()) { try { $di->seek($cnt+1); -} catch (OutOfBoundsException $ex) { +} catch (\ValueError $ex) { echo $ex->getMessage() . PHP_EOL; } echo "Is valid? " . (int) $di->valid() . PHP_EOL; ?> --EXPECTF-- -Seek position %d is out of range +DirectoryIterator::seek(): Argument #1 ($position) position %d is out of range Is valid? 0 diff --git a/ext/spl/tests/bug71735.phpt b/ext/spl/tests/bug71735.phpt index fd89cade786e9..5a22b337cfde2 100644 --- a/ext/spl/tests/bug71735.phpt +++ b/ext/spl/tests/bug71735.phpt @@ -3,11 +3,11 @@ Bug #71735 (Double-free in SplDoublyLinkedList::offsetSet) --FILE-- offsetSet(100,new DateTime('2000-01-01')); -} catch(OutOfRangeException $e) { - print $e->getMessage()."\n"; + $var_1=new SplStack(); + $var_1->offsetSet(100,new DateTime('2000-01-01')); +} catch(\ValueError $e) { + print $e->getMessage()."\n"; } ?> --EXPECT-- -Offset invalid or out of range +SplDoublyLinkedList::offsetSet(): Argument #1 ($index) is out of range diff --git a/ext/spl/tests/dit_006.phpt b/ext/spl/tests/dit_006.phpt index 42a2309c9925e..f97019dc30166 100644 --- a/ext/spl/tests/dit_006.phpt +++ b/ext/spl/tests/dit_006.phpt @@ -34,7 +34,7 @@ try { $p = 0; $di->seek($o+1); $p = 1; -} catch (\OutOfBoundsException $ex) { +} catch (\ValueError $ex) { echo $ex->getMessage() . PHP_EOL; } @@ -44,7 +44,7 @@ var_dump($n !== $m, $m === $o, $p === 0); With seek(2) we get %d With seek(0) we get %d Without seek we get %d -Seek position %d is out of range +DirectoryIterator::seek(): Argument #1 ($position) position %d is out of range bool(true) bool(true) bool(true) diff --git a/ext/spl/tests/dllist_006.phpt b/ext/spl/tests/dllist_006.phpt index 88190573e485b..3d626a4012e8f 100644 --- a/ext/spl/tests/dllist_006.phpt +++ b/ext/spl/tests/dllist_006.phpt @@ -19,30 +19,20 @@ echo "Unsetting..\n"; var_dump($a[2]); unset($a[2]); var_dump($a[2]); - - -try { - var_dump($a["1"]); -} catch (OutOfRangeException $e) { - echo "Exception: ".$e->getMessage()."\n"; -} +var_dump($a["1"]); try { var_dump($a["a"]); -} catch (OutOfRangeException $e) { - echo "Exception: ".$e->getMessage()."\n"; +} catch (\ValueError $e) { + echo $e->getMessage()."\n"; } -try { - var_dump($a["0"]); -} catch (OutOfRangeException $e) { - echo "Exception: ".$e->getMessage()."\n"; -} +var_dump($a["0"]); try { var_dump($a["9"]); -} catch (OutOfRangeException $e) { - echo "Exception: ".$e->getMessage()."\n"; +} catch (\ValueError $e) { + echo $e->getMessage()."\n"; } ?> --EXPECT-- @@ -54,6 +44,6 @@ Unsetting.. int(3) int(4) int(2) -Exception: Offset invalid or out of range +SplDoublyLinkedList::offsetGet(): Argument #1 ($index) is out of range int(1) -Exception: Offset invalid or out of range +SplDoublyLinkedList::offsetGet(): Argument #1 ($index) is out of range diff --git a/ext/spl/tests/dllist_013.phpt b/ext/spl/tests/dllist_013.phpt index 49b89d39a8b54..4a37a3698c27b 100644 --- a/ext/spl/tests/dllist_013.phpt +++ b/ext/spl/tests/dllist_013.phpt @@ -5,9 +5,9 @@ SPL: DoublyLinkedList: insert operations $dll = new SplDoublyLinkedList(); // errors try { - $dll->add(2,5); -} catch (OutOfRangeException $e) { - echo "Exception: ".$e->getMessage()."\n"; + $dll->add(2,5); +} catch (\ValueError $e) { + echo $e->getMessage()."\n"; } $dll->add(0,6); // 6 @@ -31,7 +31,7 @@ echo $dll->pop()."\n"; echo $dll->pop()."\n"; ?> --EXPECT-- -Exception: Offset invalid or out of range +SplDoublyLinkedList::add(): Argument #1 ($index) is out of range 7 7 6 diff --git a/ext/spl/tests/fileobject_003.phpt b/ext/spl/tests/fileobject_003.phpt index 4f33065d426be..3fe2c69a52bf5 100644 --- a/ext/spl/tests/fileobject_003.phpt +++ b/ext/spl/tests/fileobject_003.phpt @@ -30,14 +30,14 @@ function test($name, $lc, $lp) var_dump($f->getPath()); $l = substr($f->getPath(), -1); var_dump($l != '/' && $l != '\\' && $l == $lp); - } catch (LogicException $e) { - echo "LogicException: ".$e->getMessage()."\n"; + } catch (\Error $e) { + echo get_class($e) . ': ' . $e->getMessage() . \PHP_EOL; } try { $fo = $o->openFile(); var_dump($fo->getPathName(), $fo->getFileName(), $fo->getPath()); - } catch (LogicException $e) { - echo "LogicException: ".$e->getMessage()."\n"; + } catch (\Error $e) { + echo get_class($e) . ': ' . $e->getMessage() . \PHP_EOL; } } @@ -89,8 +89,8 @@ object(SplFileInfo)#%d (2) { bool(false) bool(true) bool(true) -LogicException: Cannot use SplFileObject with directories -LogicException: Cannot use SplFileObject with directories +Error: Cannot use SplFileObject with directories +Error: Cannot use SplFileObject with directories ===2=== object(SplFileInfo)#%d (2) { ["pathName":"SplFileInfo":private]=> @@ -107,5 +107,5 @@ object(SplFileInfo)#%d (2) { bool(false) bool(true) bool(true) -LogicException: Cannot use SplFileObject with directories -LogicException: Cannot use SplFileObject with directories +Error: Cannot use SplFileObject with directories +Error: Cannot use SplFileObject with directories diff --git a/ext/spl/tests/fileobject_setmaxlinelen_error001.phpt b/ext/spl/tests/fileobject_setmaxlinelen_error001.phpt index 6bfdfdcf50994..5aa37a4561a30 100644 --- a/ext/spl/tests/fileobject_setmaxlinelen_error001.phpt +++ b/ext/spl/tests/fileobject_setmaxlinelen_error001.phpt @@ -8,10 +8,10 @@ $s = new SplFileObject( __FILE__ ); try { $s->setMaxLineLen(-1); } -catch (DomainException $e) { - echo 'DomainException thrown'; +catch (\ValueError $e) { + echo($e->getMessage()); } ?> --EXPECT-- -DomainException thrown +SplFileObject::setMaxLineLen(): Argument #1 ($max_len) must be greater than or equal to 0 diff --git a/ext/spl/tests/fixedarray_001.phpt b/ext/spl/tests/fixedarray_001.phpt index 0c080a5fa1628..606ff0bec5e36 100644 --- a/ext/spl/tests/fixedarray_001.phpt +++ b/ext/spl/tests/fixedarray_001.phpt @@ -6,18 +6,18 @@ $a = new SplFixedArray(0); // errors try { $a[0] = "value1"; -} catch (RuntimeException $e) { - echo "Exception: ".$e->getMessage()."\n"; +} catch (\ValueError $e) { + echo $e->getMessage() . PHP_EOL; } try { var_dump($a["asdf"]); -} catch (RuntimeException $e) { - echo "Exception: ".$e->getMessage()."\n"; +} catch (\ValueError $e) { + echo $e->getMessage() . PHP_EOL; } try { unset($a[-1]); -} catch (RuntimeException $e) { - echo "Exception: ".$e->getMessage()."\n"; +} catch (\ValueError $e) { + echo $e->getMessage() . PHP_EOL; } $a->setSize(10); @@ -45,9 +45,9 @@ $a[0] = "valueNew"; var_dump($b[0]); ?> --EXPECT-- -Exception: Index invalid or out of range -Exception: Index invalid or out of range -Exception: Index invalid or out of range +Offset is out of range +Offset is out of range +Offset is out of range string(6) "value0" string(6) "value2" string(6) "value3" diff --git a/ext/spl/tests/fixedarray_002.phpt b/ext/spl/tests/fixedarray_002.phpt index f111dd1bfc0fa..45390d228211e 100644 --- a/ext/spl/tests/fixedarray_002.phpt +++ b/ext/spl/tests/fixedarray_002.phpt @@ -33,19 +33,20 @@ $a = new A; // errors try { $a[0] = "value1"; -} catch (RuntimeException $e) { - echo "Exception: ".$e->getMessage()."\n"; +} catch (\ValueError $e) { + echo $e->getMessage() . PHP_EOL; } try { var_dump($a["asdf"]); -} catch (RuntimeException $e) { - echo "Exception: ".$e->getMessage()."\n"; +} catch (\ValueError $e) { + echo $e->getMessage() . PHP_EOL; } try { unset($a[-1]); -} catch (RuntimeException $e) { - echo "Exception: ".$e->getMessage()."\n"; +} catch (\ValueError $e) { + echo $e->getMessage() . PHP_EOL; } + $a->setSize(10); @@ -69,11 +70,11 @@ var_dump(count($a), $a->getSize(), count($a) == $a->getSize()); ?> --EXPECT-- A::offsetSet -Exception: Index invalid or out of range +SplFixedArray::offsetSet(): Argument #1 ($index) is out of range A::offsetGet -Exception: Index invalid or out of range +SplFixedArray::offsetGet(): Argument #1 ($index) must be numeric A::offsetUnset -Exception: Index invalid or out of range +SplFixedArray::offsetUnset(): Argument #1 ($index) is out of range A::offsetSet A::offsetSet A::offsetSet diff --git a/ext/spl/tests/fixedarray_004.phpt b/ext/spl/tests/fixedarray_004.phpt index 054fb3d9b53ef..c3d49a94553f5 100644 --- a/ext/spl/tests/fixedarray_004.phpt +++ b/ext/spl/tests/fixedarray_004.phpt @@ -6,11 +6,11 @@ SPL: FixedArray: adding new elements $a = new SplFixedArray(10); try { - $a[] = 1; -} catch (Exception $e) { - var_dump($e->getMessage()); + $a[] = 1; +} catch (\Error $e) { + echo $e->getMessage() . PHP_EOL; } ?> --EXPECT-- -string(29) "Index invalid or out of range" +Dynamic allocation is forbidden diff --git a/ext/spl/tests/fixedarray_006.phpt b/ext/spl/tests/fixedarray_006.phpt index 2e762467c4f42..071578ddc020a 100644 --- a/ext/spl/tests/fixedarray_006.phpt +++ b/ext/spl/tests/fixedarray_006.phpt @@ -7,16 +7,13 @@ $b = 10000; $a = new SplFixedArray($b); try { - for ($i = 0; $i < 100; $i++) { - $a[] = new stdClass; - } -} catch (Exception $e) { - echo $e->getMessage(), "\n"; + for ($i = 0; $i < 100; $i++) { + $a[] = new stdClass; + } +} catch (\Error $e) { + echo $e->getMessage(), "\n"; } -print "ok\n"; - ?> --EXPECT-- -Index invalid or out of range -ok +Dynamic allocation is forbidden diff --git a/ext/spl/tests/fixedarray_012.phpt b/ext/spl/tests/fixedarray_012.phpt index df725aad4611f..729e1c63de29c 100644 --- a/ext/spl/tests/fixedarray_012.phpt +++ b/ext/spl/tests/fixedarray_012.phpt @@ -4,16 +4,9 @@ SPL: FixedArray: Assigning the object to another variable using [] getMessage(), "\n"; -} - -print "ok\n"; +$b = &$a[]; ?> ---EXPECT-- -Index invalid or out of range -ok +--EXPECTF-- +Notice: Indirect modification of overloaded element of SplFixedArray has no effect in %s on line %d + diff --git a/ext/spl/tests/fixedarray_013.phpt b/ext/spl/tests/fixedarray_013.phpt index cf43b3c7e773c..a2af17fa6226a 100644 --- a/ext/spl/tests/fixedarray_013.phpt +++ b/ext/spl/tests/fixedarray_013.phpt @@ -11,11 +11,12 @@ function test(SplFixedArray &$arr) { } try { - test($a[]); -} catch (Exception $e) { - echo $e->getMessage(), "\n"; + test($a[]); +} catch (\TypeError $e) { + echo $e->getMessage(), "\n"; } ?> ---EXPECT-- -Index invalid or out of range +--EXPECTF-- +Notice: Indirect modification of overloaded element of SplFixedArray has no effect in %s on line %d +test(): Argument #1 ($arr) must be of type SplFixedArray, null given, called in %s on line %d diff --git a/ext/spl/tests/fixedarray_014.phpt b/ext/spl/tests/fixedarray_014.phpt index a6f2fc188c6dc..ddd4b817e15da 100644 --- a/ext/spl/tests/fixedarray_014.phpt +++ b/ext/spl/tests/fixedarray_014.phpt @@ -1,15 +1,15 @@ --TEST-- -SPL: FixedArray: Trying to access inexistent item +SPL: FixedArray: Trying to access nonexistent item --FILE-- getMessage(); + $a = new SplFixedArray(1); + echo $a[0]++; +} catch (\ValueError $e) { + echo $e->getMessage(); } ?> ---EXPECT-- -Index invalid or out of range +--EXPECTF-- +Notice: Indirect modification of overloaded element of SplFixedArray has no effect in %s on line %d diff --git a/ext/spl/tests/fixedarray_020.phpt b/ext/spl/tests/fixedarray_020.phpt index c0ff6e3b436cc..cf5f8b8c7102c 100644 --- a/ext/spl/tests/fixedarray_020.phpt +++ b/ext/spl/tests/fixedarray_020.phpt @@ -9,20 +9,18 @@ var_dump(count($fa), $fa->toArray() === array_values($a)); $fa = SplFixedArray::fromArray($a, true); var_dump(count($fa), $fa->toArray() === $a, $fa->toArray() === (array)$fa); +echo "From Array with string keys, no preserve\n"; +SplFixedArray::fromArray(array("foo"=>"bar"), false); +echo "No exception\n"; + +echo "From Array with string keys, preserve\n"; try { - echo "From Array with string keys, no preserve\n"; - SplFixedArray::fromArray(array("foo"=>"bar"), false); - echo "No exception\n"; -} catch (Exception $e) { - echo "Exception: ".$e->getMessage()."\n"; -} -try { - echo "From Array with string keys, preserve\n"; SplFixedArray::fromArray(array("foo"=>"bar"), true); - echo "No exception\n"; -} catch (Exception $e) { - echo "Exception: ".$e->getMessage()."\n"; + echo "No exception" . PHP_EOL; +} catch (\ValueError $e) { + echo $e->getMessage() . PHP_EOL; } + ?> --EXPECT-- int(3) @@ -33,4 +31,4 @@ bool(true) From Array with string keys, no preserve No exception From Array with string keys, preserve -Exception: array must contain only positive integer keys +array must contain only positive integer keys diff --git a/ext/spl/tests/fixedarray_021.phpt b/ext/spl/tests/fixedarray_021.phpt index db4962ef481be..5175e3357b844 100644 --- a/ext/spl/tests/fixedarray_021.phpt +++ b/ext/spl/tests/fixedarray_021.phpt @@ -11,17 +11,17 @@ var_dump($a->count()); /* negative init value */ try { - $b = new SplFixedArray(-10); -} catch (Exception $e) { - var_dump($e->getMessage()); + $b = new SplFixedArray(-10); +} catch (\ValueError $e) { + echo $e->getMessage() . PHP_EOL; } /* resize and negative value */ $b = new SplFixedArray(); try { - $b->setSize(-5); -} catch (Exception $e) { - var_dump($e->getMessage()); + $b->setSize(-5); +} catch (\ValueError $e) { + echo $e->getMessage() . PHP_EOL; } /* calling __construct() twice */ @@ -46,7 +46,7 @@ try { foreach ($e as $k=>&$v) { var_dump($v); } -} catch (Exception $e) { +} catch (\Error $e) { var_dump($e->getMessage()); } @@ -60,15 +60,15 @@ var_dump(isset($a["0"], $a[-1]), $a["1"]); var_dump(empty($a["3"])); ?> ---EXPECTF-- +--EXPECT-- int(0) int(0) -string(35) "array size cannot be less than zero" -string(35) "array size cannot be less than zero" +SplFixedArray::__construct(): Argument #1 ($size) must be greater than or equal to 0 +SplFixedArray::setSize(): Argument #1 ($size) must be greater than or equal to 0 NULL int(0) int(0) -object(SplFixedArray)#%d (0) { +object(SplFixedArray)#1 (0) { } string(52) "An iterator cannot be used with foreach by reference" bool(false) diff --git a/ext/spl/tests/heap_004.phpt b/ext/spl/tests/heap_004.phpt index 892da20fb70e2..e30ae8f99a0ea 100644 --- a/ext/spl/tests/heap_004.phpt +++ b/ext/spl/tests/heap_004.phpt @@ -24,18 +24,18 @@ try { try { $h->insert(4); echo "inserted 4\n"; -} catch(Exception $e) { +} catch(Error $e) { echo "Exception: ".$e->getMessage()."\n"; } try { var_dump($h->extract()); -} catch(Exception $e) { +} catch(Error $e) { echo "Exception: ".$e->getMessage()."\n"; } try { var_dump($h->extract()); -} catch(Exception $e) { +} catch(Error $e) { echo "Exception: ".$e->getMessage()."\n"; } @@ -56,9 +56,9 @@ try { --EXPECT-- inserted 1 Exception: foo -Exception: Heap is corrupted, heap properties are no longer ensured. -Exception: Heap is corrupted, heap properties are no longer ensured. -Exception: Heap is corrupted, heap properties are no longer ensured. +Exception: Heap is corrupted, heap properties are no longer ensured +Exception: Heap is corrupted, heap properties are no longer ensured +Exception: Heap is corrupted, heap properties are no longer ensured Recovering.. int(1) int(2) diff --git a/ext/spl/tests/heap_009.phpt b/ext/spl/tests/heap_009.phpt index 39d0a19f4be66..15698a0ef866d 100644 --- a/ext/spl/tests/heap_009.phpt +++ b/ext/spl/tests/heap_009.phpt @@ -5,13 +5,13 @@ Thomas Koch #Hackday Webtuesday 2008-05-24 --FILE-- getMessage(),"\n"; } @@ -19,30 +19,30 @@ function testForException( $heap ) // 1. SplMinHeap empty $heap = new SplMinHeap; -testForException( $heap ); +testForeachReferenceError( $heap ); // 2. SplMinHeap non-empty $heap = new SplMinHeap; $heap->insert( 1 ); -testForException( $heap ); +testForeachReferenceError( $heap ); // 3. SplMaxHeap empty $heap = new SplMaxHeap; -testForException( $heap ); +testForeachReferenceError( $heap ); // 4. SplMaxHeap non-empty $heap = new SplMaxHeap; $heap->insert( 1 ); -testForException( $heap ); +testForeachReferenceError( $heap ); // 5. SplPriorityQueue empty $heap = new SplPriorityQueue; -testForException( $heap ); +testForeachReferenceError( $heap ); // 6. SplPriorityQueue non-empty $heap = new SplPriorityQueue; $heap->insert( 1, 2 ); -testForException( $heap ); +testForeachReferenceError( $heap ); ?> --EXPECT-- diff --git a/ext/spl/tests/heap_corruption.phpt b/ext/spl/tests/heap_corruption.phpt index 9b14a0fe0b09e..ca583f333d107 100644 --- a/ext/spl/tests/heap_corruption.phpt +++ b/ext/spl/tests/heap_corruption.phpt @@ -54,7 +54,7 @@ catch (Exception $e) { try { $heap->top(); } -catch (Exception $e) { +catch (Error $e) { echo "Corruption Exception: " . $e->getMessage() . PHP_EOL; } @@ -65,6 +65,6 @@ var_dump($heap->isCorrupted()); --EXPECT-- bool(false) Compare Exception: Compare exception -Corruption Exception: Heap is corrupted, heap properties are no longer ensured. +Corruption Exception: Heap is corrupted, heap properties are no longer ensured bool(true) bool(false) diff --git a/ext/spl/tests/heap_top_variation_002.phpt b/ext/spl/tests/heap_top_variation_002.phpt index add363eab3121..1264221a04772 100644 --- a/ext/spl/tests/heap_top_variation_002.phpt +++ b/ext/spl/tests/heap_top_variation_002.phpt @@ -18,14 +18,17 @@ $h = new SplMinHeap2(); $h->insert(4); try { $h->insert(5); -} catch (Exception $e) {} +} catch (Exception $e) { + echo $e->getMessage() . \PHP_EOL; +} // call top, should fail with corrupted heap try { $h->top(); -} catch (Exception $e) { +} catch (Error $e) { echo $e->getMessage(); } ?> --EXPECT-- -Heap is corrupted, heap properties are no longer ensured. +Corrupt heap +Heap is corrupted, heap properties are no longer ensured diff --git a/ext/spl/tests/iterator_022.phpt b/ext/spl/tests/iterator_022.phpt index ae79932828427..274fb97346815 100644 --- a/ext/spl/tests/iterator_022.phpt +++ b/ext/spl/tests/iterator_022.phpt @@ -119,7 +119,7 @@ try echo "$k=>$v\n"; } } -catch(UnexpectedValueException $e) +catch(TypeError $e) { echo $e->getMessage() . "\n"; } @@ -180,4 +180,4 @@ MyRecursiveArrayIterator::valid = false RecursiveArrayIteratorIterator::endChildren(1) RecursiveArrayIteratorIterator::callHasChildren(0) = yes/yes RecursiveArrayIteratorIterator::callGetChildren(skip) -Objects returned by RecursiveIterator::getChildren() must implement RecursiveIterator +Return value of RecursiveIterator::getChildren() must be of type RecursiveIterator, null returned diff --git a/ext/spl/tests/iterator_024.phpt b/ext/spl/tests/iterator_024.phpt index 21f0216d9b97d..1e3651b294da4 100644 --- a/ext/spl/tests/iterator_024.phpt +++ b/ext/spl/tests/iterator_024.phpt @@ -14,7 +14,7 @@ try { foreach(new RecursiveIteratorIterator(new ArrayObject($ar)) as $v) echo "$v\n"; } -catch (InvalidArgumentException $e) +catch (Error $e) { echo $e->getMessage() . "\n"; } diff --git a/ext/spl/tests/iterator_028.phpt b/ext/spl/tests/iterator_028.phpt index 5d681ccac05ef..51d1868099c8d 100644 --- a/ext/spl/tests/iterator_028.phpt +++ b/ext/spl/tests/iterator_028.phpt @@ -39,14 +39,12 @@ foreach($it as $v) echo $it->getDepth() . ": $v\n"; echo "===-1===\n"; $it->setMaxDepth(-1); var_dump($it->getMaxDepth()); -try -{ - $it->setMaxDepth(4); - $it->setMaxDepth(-2); -} -catch(Exception $e) -{ - var_dump($e->getMessage()); + +try { + $it->setMaxDepth(4); + $it->setMaxDepth(-2); +} catch (\ValueError $e) { + echo $e->getMessage() . PHP_EOL; } var_dump($it->getMaxDepth()); ?> @@ -105,5 +103,5 @@ int(0) 0: 4 ===-1=== bool(false) -string(33) "Parameter max_depth must be >= -1" +RecursiveIteratorIterator::setMaxDepth(): Argument #1 ($max_depth) must be greater or equal than -1 int(4) diff --git a/ext/spl/tests/iterator_030.phpt b/ext/spl/tests/iterator_030.phpt index 6a684ec30004b..0e22561ed1d15 100644 --- a/ext/spl/tests/iterator_030.phpt +++ b/ext/spl/tests/iterator_030.phpt @@ -15,7 +15,7 @@ try { var_dump($it->key()); } -catch(BadMethodCallException $e) +catch(Error $e) { echo $e->getMessage() . "\n"; } @@ -24,7 +24,7 @@ try { var_dump($it->current()); } -catch(BadMethodCallException $e) +catch(Error $e) { echo $e->getMessage() . "\n"; } diff --git a/ext/spl/tests/iterator_031.phpt b/ext/spl/tests/iterator_031.phpt index 247e13bfff08a..c0149e001ff1e 100644 --- a/ext/spl/tests/iterator_031.phpt +++ b/ext/spl/tests/iterator_031.phpt @@ -56,7 +56,7 @@ try { $ap->append($it); } -catch(LogicException $e) +catch(Error $e) { echo $e->getMessage() . "\n"; } @@ -67,7 +67,7 @@ try { $ap->parent__construct($it); } -catch(BadMethodCallException $e) +catch(Error $e) { echo $e->getMessage() . "\n"; } diff --git a/ext/spl/tests/iterator_032.phpt b/ext/spl/tests/iterator_032.phpt index 9f56d7574db7d..4bf49b0d13225 100644 --- a/ext/spl/tests/iterator_032.phpt +++ b/ext/spl/tests/iterator_032.phpt @@ -11,25 +11,19 @@ foreach($it as $k=>$v) var_dump($it->getPosition()); } -try -{ +try { $it->seek(0); -} -catch(OutOfBoundsException $e) -{ - echo $e->getMessage() . "\n"; +} catch (\ValueError $e) { + echo get_class($e) . ': ' . $e->getMessage() . \PHP_EOL; } $it->seek(2); var_dump($it->current()); -try -{ +try { $it->seek(3); -} -catch(OutOfBoundsException $e) -{ - echo $e->getMessage() . "\n"; +} catch (\ValueError $e) { + echo get_class($e) . ': ' . $e->getMessage() . \PHP_EOL; } $it->next(); @@ -41,7 +35,7 @@ var_dump($it->valid()); int(1) 2=>3 int(2) -Cannot seek to 0 which is below the offset 1 +ValueError: Seek position is out of bounds int(3) -Cannot seek to 3 which is behind offset 1 plus count 2 +ValueError: Seek position is out of bounds bool(false) diff --git a/ext/spl/tests/iterator_037.phpt b/ext/spl/tests/iterator_037.phpt index 1792b1cb66faa..bcff15ffe79e3 100644 --- a/ext/spl/tests/iterator_037.phpt +++ b/ext/spl/tests/iterator_037.phpt @@ -5,30 +5,23 @@ SPL: CachingIterator and __toString function test($ar, $flags) { - echo "===$flags===\n"; - $it = new CachingIterator($ar, 0); - try - { - $it->setFlags($flags); - } - catch (Exception $e) - { - echo 'Exception: ' . $e->getMessage() . "\n"; - var_dump($it->getFlags()); - return; - } - var_dump($it->getFlags()); - try - { - foreach($it as $v) - { - var_dump((string)$it); - } - } - catch (Exception $e) - { - echo 'Exception: ' . $e->getMessage() . "\n"; + echo "===$flags===\n"; + $it = new CachingIterator($ar, 0); + try { + $it->setFlags($flags); + } catch (\ValueError $e) { + echo $e->getMessage() . PHP_EOL; + var_dump($it->getFlags()); + return; } + var_dump($it->getFlags()); + try { + foreach($it as $v) { + var_dump((string)$it); + } + } catch (Exception $e) { + echo 'Exception: ' . $e->getMessage() . "\n"; + } } class MyItem @@ -72,19 +65,14 @@ try { $it = new CachingIterator($ar, CachingIterator::CALL_TOSTRING); $it->setFlags(0); +} catch (\ValueError $e) { + echo get_class($e) . ': ' . $e->getMessage() . \PHP_EOL; } -catch (Exception $e) -{ - echo 'Exception: ' . $e->getMessage() . "\n"; -} -try -{ +try { $it = new CachingIterator($ar, CachingIterator::TOSTRING_USE_INNER); $it->setFlags(0); -} -catch (Exception $e) -{ - echo 'Exception: ' . $e->getMessage() . "\n"; +} catch (\ValueError $e) { + echo get_class($e) . ': ' . $e->getMessage() . \PHP_EOL; } ?> @@ -110,20 +98,20 @@ string(3) "0:1" string(3) "1:2" string(3) "2:3" ===3=== -Exception: Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER +CachingIterator::setFlags(): Argument #1 ($flags) must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER int(0) ===5=== -Exception: Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER +CachingIterator::setFlags(): Argument #1 ($flags) must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER int(0) ===9=== -Exception: Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER +CachingIterator::setFlags(): Argument #1 ($flags) must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER int(0) ===6=== -Exception: Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER +CachingIterator::setFlags(): Argument #1 ($flags) must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER int(0) ===10=== -Exception: Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER +CachingIterator::setFlags(): Argument #1 ($flags) must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER int(0) ===X=== -Exception: Unsetting flag CALL_TO_STRING is not possible -Exception: Unsetting flag TOSTRING_USE_INNER is not possible +ValueError: CachingIterator::setFlags(): Argument #1 ($flags) cannot unset flag CALL_TO_STRING +ValueError: CachingIterator::setFlags(): Argument #1 ($flags) cannot unset flag TOSTRING_USE_INNER diff --git a/ext/spl/tests/iterator_069.phpt b/ext/spl/tests/iterator_069.phpt index 975fbe2f8e194..c0430a70f6d9c 100644 --- a/ext/spl/tests/iterator_069.phpt +++ b/ext/spl/tests/iterator_069.phpt @@ -10,11 +10,12 @@ $recArrIt = new RecursiveArrayIterator($arrOb->getIterator()); $recItIt = new RecursiveIteratorIterator($recArrIt); -foreach ($recItIt as &$val) echo "$val\n"; +try { + foreach ($recItIt as &$val) echo "$val\n"; +} catch (\Error $e) { + echo $e->getMessage() . \PHP_EOL; +} ?> ---EXPECTF-- -Fatal error: Uncaught RuntimeException: An iterator cannot be used with foreach by reference in %s:%d -Stack trace: -#0 {main} - thrown in %s on line %d +--EXPECT-- +An iterator cannot be used with foreach by reference diff --git a/ext/spl/tests/multiple_iterator_001.phpt b/ext/spl/tests/multiple_iterator_001.phpt index 56a08da272dd6..309e7875dbd14 100644 --- a/ext/spl/tests/multiple_iterator_001.phpt +++ b/ext/spl/tests/multiple_iterator_001.phpt @@ -28,13 +28,13 @@ foreach($m as $key => $value) { } try { $m->current(); -} catch(RuntimeException $e) { - echo "RuntimeException thrown: " . $e->getMessage() . "\n"; +} catch(\Throwable $e) { + echo get_class($e) . ': ' . $e->getMessage() . \PHP_EOL; } try { $m->key(); -} catch(RuntimeException $e) { - echo "RuntimeException thrown: " . $e->getMessage() . "\n"; +} catch(\Throwable $e) { + echo get_class($e) . ': ' . $e->getMessage() . \PHP_EOL; } echo "-- Flags = MultipleIterator::MIT_NEED_ANY | MultipleIterator::MIT_KEYS_NUMERIC --\n"; @@ -61,8 +61,8 @@ $m->setFlags(MultipleIterator::MIT_NEED_ALL | MultipleIterator::MIT_KEYS_ASSOC); $m->rewind(); try { $m->current(); -} catch(InvalidArgumentException $e) { - echo "InvalidArgumentException thrown: " . $e->getMessage() . "\n"; +} catch(\Throwable $e) { + echo get_class($e) . ': ' . $e->getMessage() . \PHP_EOL; } echo "-- Flags |= MultipleIterator::MIT_KEYS_ASSOC --\n"; @@ -78,17 +78,17 @@ foreach($m as $key => $value) { echo "-- Associate with invalid value --\n"; try { - $m->attachIterator($iter3, new stdClass()); -} catch(InvalidArgumentException $e) { - echo "InvalidArgumentException thrown: " . $e->getMessage() . "\n"; + $m->attachIterator($iter3, new stdClass()); +} catch (\TypeError $e) { + echo $e->getMessage() . PHP_EOL; } echo "-- Associate with duplicate value --\n"; try { $m->attachIterator($iter3, "iter1"); -} catch(InvalidArgumentException $e) { - echo "InvalidArgumentException thrown: " . $e->getMessage() . "\n"; +} catch(\Throwable $e) { + echo get_class($e) . ': ' . $e->getMessage() . \PHP_EOL; } echo "-- Count, contains, detach, count, contains, iterate --\n"; @@ -103,7 +103,7 @@ foreach($m as $key => $value) { } ?> ---EXPECTF-- +--EXPECT-- -- Default flags, no iterators -- bool(false) -- Default flags, MultipleIterator::MIT_NEED_ALL | MultipleIterator::MIT_KEYS_NUMERIC -- @@ -122,7 +122,7 @@ array(3) { [1]=> int(1) [2]=> - object(stdClass)#%d (0) { + object(stdClass)#4 (0) { } } array(3) { @@ -141,8 +141,8 @@ array(3) { [2]=> string(6) "string" } -RuntimeException thrown: Called current() with non valid sub iterator -RuntimeException thrown: Called key() with non valid sub iterator +Error: Called current() with non valid sub iterator +Error: Called key() with non valid sub iterator -- Flags = MultipleIterator::MIT_NEED_ANY | MultipleIterator::MIT_KEYS_NUMERIC -- bool(true) array(3) { @@ -159,7 +159,7 @@ array(3) { [1]=> int(1) [2]=> - object(stdClass)#%d (0) { + object(stdClass)#4 (0) { } } array(3) { @@ -209,7 +209,7 @@ array(3) { [1]=> int(1) [2]=> - object(stdClass)#%d (0) { + object(stdClass)#4 (0) { } } array(3) { @@ -245,7 +245,7 @@ array(3) { int(3) } -- Flags |= MultipleIterator::MIT_KEYS_ASSOC, with iterator associated with NULL -- -InvalidArgumentException thrown: Sub-Iterator is associated with NULL +Error: Sub-Iterator is associated with NULL -- Flags |= MultipleIterator::MIT_KEYS_ASSOC -- array(3) { ["iter1"]=> @@ -261,7 +261,7 @@ array(3) { ["iter2"]=> int(1) [3]=> - object(stdClass)#%d (0) { + object(stdClass)#4 (0) { } } array(3) { @@ -297,9 +297,9 @@ array(3) { int(3) } -- Associate with invalid value -- -InvalidArgumentException thrown: Info must be NULL, integer or string +MultipleIterator::attachIterator(): Argument #2 ($info) must be int|string|null, object given -- Associate with duplicate value -- -InvalidArgumentException thrown: Key duplication error +InvalidArgumentException: Key duplication error -- Count, contains, detach, count, contains, iterate -- int(3) bool(true) @@ -316,7 +316,7 @@ array(2) { ["iter1"]=> int(1) [3]=> - object(stdClass)#%d (0) { + object(stdClass)#4 (0) { } } array(2) { diff --git a/ext/spl/tests/pqueue_002.phpt b/ext/spl/tests/pqueue_002.phpt index ee9a5f30caeff..af2686074af18 100644 --- a/ext/spl/tests/pqueue_002.phpt +++ b/ext/spl/tests/pqueue_002.phpt @@ -24,18 +24,18 @@ try { try { $h->insert(4, 1); echo "inserted 4\n"; -} catch(Exception $e) { +} catch(Error $e) { echo "Exception: ".$e->getMessage()."\n"; } try { var_dump($h->extract()); -} catch(Exception $e) { +} catch(Error $e) { echo "Exception: ".$e->getMessage()."\n"; } try { var_dump($h->extract()); -} catch(Exception $e) { +} catch(Error $e) { echo "Exception: ".$e->getMessage()."\n"; } @@ -56,9 +56,9 @@ try { --EXPECT-- inserted 1 Exception: foo -Exception: Heap is corrupted, heap properties are no longer ensured. -Exception: Heap is corrupted, heap properties are no longer ensured. -Exception: Heap is corrupted, heap properties are no longer ensured. +Exception: Heap is corrupted, heap properties are no longer ensured +Exception: Heap is corrupted, heap properties are no longer ensured +Exception: Heap is corrupted, heap properties are no longer ensured Recovering.. int(1) int(2) diff --git a/ext/spl/tests/recursive_tree_iterator_008.phpt b/ext/spl/tests/recursive_tree_iterator_008.phpt index fbdc3a5cb1790..5c1fe777d74b5 100644 --- a/ext/spl/tests/recursive_tree_iterator_008.phpt +++ b/ext/spl/tests/recursive_tree_iterator_008.phpt @@ -18,16 +18,17 @@ for($i = 0; $i < 6; ++$i) { foreach($it as $k => $v) { echo "[$k] => $v\n"; } + try { - $it->setPrefixPart(-1, ""); - $it->setPrefixPart(6, ""); -} catch (OutOfRangeException $e) { - echo "OutOfRangeException thrown\n"; + $it->setPrefixPart(-1, ""); + $it->setPrefixPart(6, ""); +} catch (\ValueError $e) { + echo $e->getMessage() . PHP_EOL; } try { - $it->setPrefixPart(6, ""); -} catch (OutOfRangeException $e) { - echo "OutOfRangeException thrown\n"; + $it->setPrefixPart(6, ""); +} catch (\ValueError $e) { + echo $e->getMessage() . PHP_EOL; } ?> --EXPECT-- @@ -35,5 +36,5 @@ try { [0] => 0145b [c] => 045Array [0] => 0245d -OutOfRangeException thrown -OutOfRangeException thrown +RecursiveTreeIterator::setPrefixPart(): Argument #2 ($value) must be one of RecursiveTreeIterator::PREFIX_* +RecursiveTreeIterator::setPrefixPart(): Argument #2 ($value) must be one of RecursiveTreeIterator::PREFIX_* diff --git a/ext/spl/tests/regexIterator_setMode_error.phpt b/ext/spl/tests/regexIterator_setMode_error.phpt index 4816896d8a464..8b63974ece77c 100644 --- a/ext/spl/tests/regexIterator_setMode_error.phpt +++ b/ext/spl/tests/regexIterator_setMode_error.phpt @@ -11,14 +11,12 @@ $regexIterator = new RegexIterator(new ArrayIterator($array), "/f/"); var_dump($regexIterator->getMode()); try { - $regexIterator->setMode(7); -} catch (InvalidArgumentException $e) { - var_dump($e->getMessage()); - var_dump($e->getCode()); + $regexIterator->setMode(7); +} catch (\ValueError $e) { + echo $e->getMessage() . PHP_EOL; } ?> ---EXPECTF-- -int(0) -string(14) "Illegal mode 7" +--EXPECT-- int(0) +Illegal mode 7 diff --git a/ext/spl/tests/spl_autoload_001.phpt b/ext/spl/tests/spl_autoload_001.phpt index 6025ac653833b..7800ee749fd32 100644 --- a/ext/spl/tests/spl_autoload_001.phpt +++ b/ext/spl/tests/spl_autoload_001.phpt @@ -64,13 +64,10 @@ var_dump(class_exists("TestClass", true)); echo "===NOFUNCTION===\n"; -try -{ +try { spl_autoload_register("unavailable_autoload_function"); -} -catch(Exception $e) -{ - echo 'Exception: ' . $e->getMessage() . "\n"; +} catch (\TypeError $e) { + echo $e->getMessage() . PHP_EOL; } ?> @@ -103,4 +100,4 @@ TestFunc2(TestClass) %stestclass.class.inc bool(true) ===NOFUNCTION=== -Exception: Function 'unavailable_autoload_function' not found (function 'unavailable_autoload_function' not found or invalid function name) +Function 'unavailable_autoload_function' not found (function 'unavailable_autoload_function' not found or invalid function name) diff --git a/ext/spl/tests/spl_autoload_005.phpt b/ext/spl/tests/spl_autoload_005.phpt index 53fbf27663fe2..5c610ba42531d 100644 --- a/ext/spl/tests/spl_autoload_005.phpt +++ b/ext/spl/tests/spl_autoload_005.phpt @@ -19,13 +19,10 @@ class MyAutoLoader { } } -try -{ - spl_autoload_register(array('MyAutoLoader', 'autoLoad'), true); -} -catch(Exception $e) -{ - echo 'Exception: ' . $e->getMessage() . "\n"; +try { + spl_autoload_register(array('MyAutoLoader', 'autoLoad'), true); +} catch (\TypeError $e) { + echo $e->getMessage() . PHP_EOL; } // and @@ -46,7 +43,7 @@ catch(Exception $e) ?> --EXPECT-- -Exception: Passed array specifies a non static method but no object (non-static method MyAutoLoader::autoLoad() cannot be called statically) +Passed array specifies a non static method but no object (non-static method MyAutoLoader::autoLoad() cannot be called statically) MyAutoLoader::autoLoad(TestClass) MyAutoLoader::autoThrow(TestClass) Exception: Unavailable diff --git a/ext/spl/tests/spl_autoload_007.phpt b/ext/spl/tests/spl_autoload_007.phpt index db5f394260f35..a96d66e9e60a9 100644 --- a/ext/spl/tests/spl_autoload_007.phpt +++ b/ext/spl/tests/spl_autoload_007.phpt @@ -39,16 +39,13 @@ $funcs = array( foreach($funcs as $idx => $func) { - if ($idx) echo "\n"; - try - { + if ($idx) echo "\n"; + try { var_dump($func); spl_autoload_register($func); echo "ok\n"; - } - catch (Exception $e) - { - echo $e->getMessage() . "\n"; + } catch (\TypeError $e) { + echo $e->getMessage() . PHP_EOL; } } diff --git a/ext/spl/tests/spl_autoload_008.phpt b/ext/spl/tests/spl_autoload_008.phpt index eadc861ca16a2..7fb711ae067ca 100644 --- a/ext/spl/tests/spl_autoload_008.phpt +++ b/ext/spl/tests/spl_autoload_008.phpt @@ -42,20 +42,16 @@ foreach($funcs as $idx => $func) { echo "====$idx====\n"; - try - { - var_dump($func); - spl_autoload_register($func); - if (count(spl_autoload_functions())) - { - echo "registered\n"; + try { + var_dump($func); + spl_autoload_register($func); + if (count(spl_autoload_functions())) { + echo "registered\n"; - var_dump(class_exists("NoExistingTestClass", true)); - } - } - catch (Exception $e) - { - echo get_class($e) . ": " . $e->getMessage() . "\n"; + var_dump(class_exists("NoExistingTestClass", true)); + } + } catch (\TypeError|\Exception $e) { + echo get_class($e) . ': ' . $e->getMessage() . PHP_EOL; } spl_autoload_unregister($func); @@ -78,7 +74,7 @@ Exception: Bla int(0) ====2==== string(22) "MyAutoLoader::dynaLoad" -LogicException: Function 'MyAutoLoader::dynaLoad' not callable (non-static method MyAutoLoader::dynaLoad() cannot be called statically) +TypeError: Function 'MyAutoLoader::dynaLoad' not callable (non-static method MyAutoLoader::dynaLoad() cannot be called statically) int(0) ====3==== array(2) { @@ -98,7 +94,7 @@ array(2) { [1]=> string(8) "dynaLoad" } -LogicException: Passed array specifies a non static method but no object (non-static method MyAutoLoader::dynaLoad() cannot be called statically) +TypeError: Passed array specifies a non static method but no object (non-static method MyAutoLoader::dynaLoad() cannot be called statically) int(0) ====5==== array(2) { diff --git a/ext/spl/tests/spl_caching_iterator_constructor_flags.phpt b/ext/spl/tests/spl_caching_iterator_constructor_flags.phpt index 29bae9469d6f3..5baf52ce94482 100644 --- a/ext/spl/tests/spl_caching_iterator_constructor_flags.phpt +++ b/ext/spl/tests/spl_caching_iterator_constructor_flags.phpt @@ -8,16 +8,16 @@ TestFest London May 2009 //line 681 ... $array = array(array(7,8,9),1,2,3,array(4,5,6)); $arrayIterator = new ArrayIterator($array); -try { $test = new CachingIterator($arrayIterator, 0); $test = new CachingIterator($arrayIterator, 1); $test = new CachingIterator($arrayIterator, 2); -$test = new CachingIterator($arrayIterator, 3); // this throws an exception -} catch (InvalidArgumentException $e){ - print $e->getMessage() . "\n"; -} +try { + $test = new CachingIterator($arrayIterator, 3); // this throws an exception +} catch (\ValueError $e) { + echo $e->getMessage() . PHP_EOL; +} ?> --EXPECT-- -Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER +CachingIterator::__construct(): Argument #2 ($flags) must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER diff --git a/ext/spl/tests/spl_iterator_getcallchildren.phpt b/ext/spl/tests/spl_iterator_getcallchildren.phpt index e14acd12daacd..6696fedac8e42 100644 --- a/ext/spl/tests/spl_iterator_getcallchildren.phpt +++ b/ext/spl/tests/spl_iterator_getcallchildren.phpt @@ -14,13 +14,10 @@ var_dump($test->current()); $test->next(); var_dump($test->current()); try { - $output = $test->callGetChildren(); -} catch (InvalidArgumentException $ilae){ - $output = null; - print "invalid argument exception\n"; + var_dump($test->callGetChildren()); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; } -var_dump($output); - ?> --EXPECT-- @@ -33,5 +30,4 @@ var_dump($output); int(9) } int(7) -invalid argument exception -NULL +ArrayIterator::__construct(): Argument #1 ($array) must be array|object, int given diff --git a/ext/spl/tests/spl_limit_iterator_check_limits.phpt b/ext/spl/tests/spl_limit_iterator_check_limits.phpt index 83b99b5c85894..669b055f82cc1 100644 --- a/ext/spl/tests/spl_limit_iterator_check_limits.phpt +++ b/ext/spl/tests/spl_limit_iterator_check_limits.phpt @@ -9,27 +9,22 @@ TestFest London May 2009 $arrayIterator = new ArrayIterator($array); try { - $limitIterator = new LimitIterator($arrayIterator, -1); -} catch (OutOfRangeException $e){ - print $e->getMessage(). "\n"; -} - - -try { - $limitIterator = new LimitIterator($arrayIterator, 0, -2); -} catch (OutOfRangeException $e){ - print $e->getMessage() . "\n"; + var_dump(new LimitIterator($arrayIterator, -1)); +} catch (\ValueError $e) { + echo $e->getMessage() . PHP_EOL; } try { - $limitIterator = new LimitIterator($arrayIterator, 0, -1); -} catch (OutOfRangeException $e){ - print $e->getMessage() . "\n"; + var_dump(new LimitIterator($arrayIterator, 0, -2)); +} catch (\ValueError $e) { + echo $e->getMessage() . PHP_EOL; } - +var_dump(new LimitIterator($arrayIterator, 0, -1)); ?> --EXPECT-- -Parameter offset must be >= 0 -Parameter count must either be -1 or a value greater than or equal 0 +LimitIterator::__construct(): Argument #1 ($iterator) must be greater or equal to 0 +LimitIterator::__construct(): Argument #2 ($offset) must be greater or equal to 0 +object(LimitIterator)#3 (0) { +} diff --git a/ext/spl/tests/spl_pq_top_error_corrupt.phpt b/ext/spl/tests/spl_pq_top_error_corrupt.phpt index 838e763447f88..a4c062401d6bf 100644 --- a/ext/spl/tests/spl_pq_top_error_corrupt.phpt +++ b/ext/spl/tests/spl_pq_top_error_corrupt.phpt @@ -29,10 +29,10 @@ try { try { $priorityQueue->top(); -} catch (RuntimeException $e) { +} catch (Error $e) { echo "Exception: ".$e->getMessage().PHP_EOL; } ?> --EXPECT-- -Exception: Heap is corrupted, heap properties are no longer ensured. +Exception: Heap is corrupted, heap properties are no longer ensured diff --git a/ext/spl/tests/unserialize_errors.phpt b/ext/spl/tests/unserialize_errors.phpt index 237d0673c46be..73e09691ff2a0 100644 --- a/ext/spl/tests/unserialize_errors.phpt +++ b/ext/spl/tests/unserialize_errors.phpt @@ -25,7 +25,7 @@ try { try { unserialize('O:11:"ArrayObject":3:{i:0;i:0;i:1;i:0;i:2;a:0:{}}'); -} catch (Exception $e) { +} catch (\TypeError $e) { echo $e->getMessage(), "\n"; } @@ -51,7 +51,7 @@ try { try { unserialize('O:13:"ArrayIterator":3:{i:0;i:0;i:1;i:0;i:2;a:0:{}}'); -} catch (Exception $e) { +} catch (\TypeError $e) { echo $e->getMessage(), "\n"; } @@ -59,25 +59,25 @@ echo "SplDoublyLinkedList:\n"; try { unserialize('O:19:"SplDoublyLinkedList":0:{}'); -} catch (Exception $e) { +} catch (Error $e) { echo $e->getMessage(), "\n"; } try { unserialize('O:19:"SplDoublyLinkedList":3:{i:0;b:1;i:1;a:0:{}i:2;a:0:{}}'); -} catch (Exception $e) { +} catch (Error $e) { echo $e->getMessage(), "\n"; } try { unserialize('O:19:"SplDoublyLinkedList":3:{i:0;i:0;i:1;a:0:{}i:2;i:0;}'); -} catch (Exception $e) { +} catch (Error $e) { echo $e->getMessage(), "\n"; } try { unserialize('O:19:"SplDoublyLinkedList":3:{i:0;i:0;i:1;i:0;i:2;a:0:{}}'); -} catch (Exception $e) { +} catch (Error $e) { echo $e->getMessage(), "\n"; } @@ -85,46 +85,46 @@ echo "SplObjectStorage:\n"; try { unserialize('O:16:"SplObjectStorage":0:{}'); -} catch (Exception $e) { +} catch (Error $e) { echo $e->getMessage(), "\n"; } try { unserialize('O:16:"SplObjectStorage":2:{i:0;i:0;i:1;a:0:{}}'); -} catch (Exception $e) { +} catch (Error $e) { echo $e->getMessage(), "\n"; } try { unserialize('O:16:"SplObjectStorage":2:{i:0;a:0:{}i:1;i:1;}'); -} catch (Exception $e) { +} catch (Error $e) { echo $e->getMessage(), "\n"; } try { unserialize('O:16:"SplObjectStorage":2:{i:0;a:1:{i:0;i:0;}i:1;a:0:{}}'); -} catch (Exception $e) { +} catch (ValueError $e) { echo $e->getMessage(), "\n"; } try { unserialize('O:16:"SplObjectStorage":2:{i:0;a:2:{i:0;i:0;i:1;i:0;}i:1;a:0:{}}'); -} catch (Exception $e) { +} catch (TypeError $e) { echo $e->getMessage(), "\n"; } ?> ---EXPECTF-- +--EXPECT-- ArrayObject: Incomplete or ill-typed serialization data Incomplete or ill-typed serialization data Incomplete or ill-typed serialization data -Passed variable is not an array or object +Passed variable must be array|object, int given ArrayIterator: Incomplete or ill-typed serialization data Incomplete or ill-typed serialization data Incomplete or ill-typed serialization data -Passed variable is not an array or object +Passed variable must be array|object, int given SplDoublyLinkedList: Incomplete or ill-typed serialization data Incomplete or ill-typed serialization data @@ -135,4 +135,4 @@ Incomplete or ill-typed serialization data Incomplete or ill-typed serialization data Incomplete or ill-typed serialization data Odd number of elements -Non-object key +Key must be an object