From f33e5efc0a03129e751fa74375baef37bfbc165d Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Sat, 17 Aug 2019 23:28:38 +0200 Subject: [PATCH 1/4] Converting warnings to exceptions in array related functions. --- Zend/zend_vm_def.h | 2 +- Zend/zend_vm_execute.h | 6 +- ext/standard/array.c | 150 ++++----- ext/standard/tests/array/array_chunk.phpt | 21 -- ext/standard/tests/array/array_chunk2.phpt | 24 +- .../tests/array/array_chunk_variation10.phpt | 13 +- .../tests/array/array_chunk_variation11.phpt | 13 +- .../tests/array/array_chunk_variation12.phpt | 13 +- .../tests/array/array_chunk_variation13.phpt | 13 +- .../tests/array/array_chunk_variation14.phpt | 13 +- .../tests/array/array_chunk_variation15.phpt | 13 +- .../tests/array/array_chunk_variation16.phpt | 13 +- .../tests/array/array_chunk_variation17.phpt | 13 +- .../tests/array/array_chunk_variation18.phpt | 13 +- .../tests/array/array_chunk_variation19.phpt | 13 +- .../tests/array/array_chunk_variation20.phpt | 13 +- .../tests/array/array_chunk_variation21.phpt | 13 +- .../tests/array/array_chunk_variation22.phpt | 13 +- .../tests/array/array_chunk_variation23.phpt | 13 +- .../tests/array/array_chunk_variation24.phpt | 13 +- .../tests/array/array_chunk_variation25.phpt | 13 +- .../tests/array/array_chunk_variation26.phpt | 13 +- .../tests/array/array_chunk_variation27.phpt | 13 +- .../tests/array/array_chunk_variation28.phpt | 13 +- .../tests/array/array_chunk_variation29.phpt | 13 +- .../tests/array/array_chunk_variation30.phpt | 13 +- .../tests/array/array_chunk_variation31.phpt | 13 +- .../tests/array/array_chunk_variation32.phpt | 13 +- .../tests/array/array_chunk_variation5.phpt | 52 ++-- .../tests/array/array_chunk_variation8.phpt | 13 +- .../tests/array/array_chunk_variation9.phpt | 13 +- .../tests/array/array_column_error.phpt | 48 +-- .../tests/array/array_combine_error2.phpt | 39 ++- .../tests/array/array_count_values.phpt | 16 +- .../tests/array/array_count_values2.phpt | 31 +- .../array/array_count_values_variation.phpt | 22 +- .../tests/array/array_fill_error.phpt | 15 +- ext/standard/tests/array/array_flip.phpt | 47 ++- .../tests/array/array_flip_variation4.phpt | 39 +-- .../tests/array/array_multisort_error.phpt | 22 +- .../array/array_multisort_variation1.phpt | 83 ++--- .../array/array_multisort_variation2.phpt | 88 ++---- .../array/array_multisort_variation3.phpt | 86 ++---- ext/standard/tests/array/array_pad.phpt | 17 +- .../tests/array/array_push_error2.phpt | 11 +- ext/standard/tests/array/array_rand.phpt | 54 ++-- .../tests/array/array_rand_variation5.phpt | 48 +-- ext/standard/tests/array/array_replace.phpt | 24 +- ext/standard/tests/array/bug42177.phpt | 10 +- ext/standard/tests/array/bug43495.phpt | 17 +- ext/standard/tests/array/bug61058.phpt | 11 +- ext/standard/tests/array/bug65251.phpt | 10 +- ext/standard/tests/array/bug70713.phpt | 11 +- ext/standard/tests/array/bug77395.phpt | 9 +- .../tests/array/compact_variation1.phpt | 43 +-- ext/standard/tests/array/count_errors.phpt | 74 +++++ ext/standard/tests/array/count_invalid.phpt | 81 ++--- ext/standard/tests/array/count_recursive.phpt | 92 +----- .../tests/array/count_variation3.phpt | 13 +- ext/standard/tests/array/extract_error.phpt | 32 +- ext/standard/tests/array/max.phpt | 34 +- ext/standard/tests/array/min.phpt | 34 +- .../tests/array/range_bug70239_0.phpt | 10 +- .../tests/array/range_bug70239_1.phpt | 10 +- .../tests/array/range_bug70239_2.phpt | 9 +- .../tests/array/range_bug70239_3.phpt | 9 +- ext/standard/tests/array/range_errors.phpt | 119 ++++--- ext/standard/tests/array/sizeof_basic1.phpt | 79 +++-- ext/standard/tests/array/sizeof_object2.phpt | 107 +++---- .../tests/array/sizeof_variation1.phpt | 278 ++++++----------- .../tests/array/sizeof_variation4.phpt | 290 ++++++------------ run-tests.php | 15 +- 72 files changed, 1214 insertions(+), 1453 deletions(-) delete mode 100644 ext/standard/tests/array/array_chunk.phpt create mode 100644 ext/standard/tests/array/count_errors.phpt diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index a0aead301ce74..61a4f5ac6d4e0 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -8616,7 +8616,7 @@ ZEND_VM_COLD_CONST_HANDLER(190, ZEND_COUNT, CONST|TMPVAR|CV, UNUSED) } else { count = 1; } - zend_error(E_WARNING, "%s(): Parameter must be an array or an object that implements Countable", opline->extended_value ? "sizeof" : "count"); + zend_type_error("Parameter must be an array or an object that implements Countable"); break; } diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 29d6d3e778985..0cabaaf6f5273 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -9558,7 +9558,7 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_CONST_ } else { count = 1; } - zend_error(E_WARNING, "%s(): Parameter must be an array or an object that implements Countable", opline->extended_value ? "sizeof" : "count"); + zend_type_error("Parameter must be an array or an object that implements Countable"); break; } @@ -16687,7 +16687,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_TMPVAR_UNUSED_HANDL } else { count = 1; } - zend_error(E_WARNING, "%s(): Parameter must be an array or an object that implements Countable", opline->extended_value ? "sizeof" : "count"); + zend_type_error("Parameter must be an array or an object that implements Countable"); break; } @@ -47323,7 +47323,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_CV_UNUSED_HANDLER(Z } else { count = 1; } - zend_error(E_WARNING, "%s(): Parameter must be an array or an object that implements Countable", opline->extended_value ? "sizeof" : "count"); + zend_type_error("Parameter must be an array or an object that implements Countable"); break; } diff --git a/ext/standard/array.c b/ext/standard/array.c index 70523d479ef4f..432cc48c390f6 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -735,7 +735,7 @@ PHPAPI zend_long php_count_recursive(HashTable *ht) /* {{{ */ if (!(GC_FLAGS(ht) & GC_IMMUTABLE)) { if (GC_IS_RECURSIVE(ht)) { - php_error_docref(NULL, E_WARNING, "recursion detected"); + zend_throw_error(NULL, "Recursion detected"); return 0; } GC_PROTECT_RECURSION(ht); @@ -773,9 +773,8 @@ PHP_FUNCTION(count) switch (Z_TYPE_P(array)) { case IS_NULL: - php_error_docref(NULL, E_WARNING, "Parameter must be an array or an object that implements Countable"); - RETURN_LONG(0); - break; + zend_type_error("Parameter must be an array or an object that implements Countable"); + return; case IS_ARRAY: if (mode != COUNT_RECURSIVE) { cnt = zend_array_count(Z_ARRVAL_P(array)); @@ -804,14 +803,12 @@ PHP_FUNCTION(count) } /* If There's no handler and it doesn't implement Countable then add a warning */ - php_error_docref(NULL, E_WARNING, "Parameter must be an array or an object that implements Countable"); - RETURN_LONG(1); - break; + zend_type_error("Parameter must be an array or an object that implements Countable"); + return; } default: - php_error_docref(NULL, E_WARNING, "Parameter must be an array or an object that implements Countable"); - RETURN_LONG(1); - break; + zend_type_error("Parameter must be an array or an object that implements Countable"); + return; } } /* }}} */ @@ -972,6 +969,7 @@ static int php_array_user_compare(const void *a, const void *b) /* {{{ */ /* check if comparison function is valid */ #define PHP_ARRAY_CMP_FUNC_CHECK(func_name) \ if (!zend_is_callable(*func_name, 0, NULL)) { \ + /* Convert to Exception ? */ \ php_error_docref(NULL, E_WARNING, "Invalid comparison function"); \ BG(user_compare_fci) = old_user_compare_fci; \ BG(user_compare_fci_cache) = old_user_compare_fci_cache; \ @@ -1226,7 +1224,7 @@ PHP_FUNCTION(current) } /* }}} */ -/* {{{ proto mixed key(array array_arg) +/* {{{ proto int|string|null key(array array_arg) Return the key of the element currently pointed to by the internal array pointer */ PHP_FUNCTION(key) { @@ -1240,7 +1238,9 @@ PHP_FUNCTION(key) } /* }}} */ -/* {{{ proto mixed min(mixed arg1 [, mixed arg2 [, mixed ...]]) +/* {{{ + * proto mixed min(array values) + * proto mixed min(mixed arg1 [, mixed arg2 [, mixed ...]]) Return the lowest value in an array or a series of arguments */ PHP_FUNCTION(min) { @@ -1256,14 +1256,14 @@ PHP_FUNCTION(min) zval *result; if (Z_TYPE(args[0]) != IS_ARRAY) { - php_error_docref(NULL, E_WARNING, "When only one parameter is given, it must be an array"); - RETVAL_NULL(); + zend_type_error("When only one parameter is given, it must be an array"); + return; } else { if ((result = zend_hash_minmax(Z_ARRVAL(args[0]), php_array_data_compare, 0)) != NULL) { ZVAL_COPY_DEREF(return_value, result); } else { - php_error_docref(NULL, E_WARNING, "Array must contain at least one element"); - RETVAL_FALSE; + zend_throw_error(NULL, "Array must contain at least one element"); + return; } } } else { @@ -1285,7 +1285,9 @@ PHP_FUNCTION(min) } /* }}} */ -/* {{{ proto mixed max(mixed arg1 [, mixed arg2 [, mixed ...]]) +/* {{{ + * proto mixed max(array values) + * proto mixed max(mixed arg1 [, mixed arg2 [, mixed ...]]) Return the highest value in an array or a series of arguments */ PHP_FUNCTION(max) { @@ -1301,14 +1303,14 @@ PHP_FUNCTION(max) zval *result; if (Z_TYPE(args[0]) != IS_ARRAY) { - php_error_docref(NULL, E_WARNING, "When only one parameter is given, it must be an array"); - RETVAL_NULL(); + zend_type_error("When only one parameter is given, it must be an array"); + return; } else { if ((result = zend_hash_minmax(Z_ARRVAL(args[0]), php_array_data_compare, 1)) != NULL) { ZVAL_COPY_DEREF(return_value, result); } else { - php_error_docref(NULL, E_WARNING, "Array must contain at least one element"); - RETVAL_FALSE; + zend_throw_error(NULL, "Array must contain at least one element"); + return; } } } else { @@ -1395,7 +1397,7 @@ static int php_array_walk(zval *array, zval *userdata, int recursive) /* {{{ */ SEPARATE_ARRAY(zv); thash = Z_ARRVAL_P(zv); if (GC_IS_RECURSIVE(thash)) { - php_error_docref(NULL, E_WARNING, "recursion detected"); + zend_throw_error(NULL, "Recursion detected"); result = FAILURE; break; } @@ -1446,9 +1448,8 @@ static int php_array_walk(zval *array, zval *userdata, int recursive) /* {{{ */ target_hash = Z_OBJPROP_P(array); pos = zend_hash_iterator_pos(ht_iter, target_hash); } else { - php_error_docref(NULL, E_WARNING, "Iterated value is no longer an array or object"); - result = FAILURE; - break; + zend_type_error("Iterated value is no longer an array or object"); + return -1; } } while (!EG(exception)); @@ -2448,23 +2449,24 @@ PHP_FUNCTION(extract) extract_type &= 0xff; if (extract_type < EXTR_OVERWRITE || extract_type > EXTR_IF_EXISTS) { - php_error_docref(NULL, E_WARNING, "Invalid extract type"); + zend_throw_error(NULL, "Invalid extract type"); return; } if (extract_type > EXTR_SKIP && extract_type <= EXTR_PREFIX_IF_EXISTS && ZEND_NUM_ARGS() < 3) { - php_error_docref(NULL, E_WARNING, "specified extract type requires the prefix parameter"); + zend_throw_error(NULL, "specified extract type requires the prefix parameter"); return; } if (prefix) { if (ZSTR_LEN(prefix) && !php_valid_var_name(ZSTR_VAL(prefix), ZSTR_LEN(prefix))) { - php_error_docref(NULL, E_WARNING, "prefix is not a valid identifier"); + zend_throw_error(NULL, "prefix is not a valid identifier"); return; } } if (zend_forbid_dynamic_call("extract()") == FAILURE) { + /* TODO Elevate to exception ? */ return; } @@ -2551,7 +2553,7 @@ static void php_compact_var(HashTable *eg_active_symbol_table, zval *return_valu } else if (Z_TYPE_P(entry) == IS_ARRAY) { if (Z_REFCOUNTED_P(entry)) { if (Z_IS_RECURSIVE_P(entry)) { - php_error_docref(NULL, E_WARNING, "recursion detected"); + zend_throw_error(NULL, "Recursion detected"); return; } Z_PROTECT_RECURSION_P(entry); @@ -2602,7 +2604,7 @@ PHP_FUNCTION(compact) } /* }}} */ -/* {{{ proto array|false array_fill(int start_key, int num, mixed val) +/* {{{ proto array array_fill(int start_key, int num, mixed val) Create an array containing num elements starting with index start_key each initialized to val */ PHP_FUNCTION(array_fill) { @@ -2617,11 +2619,12 @@ PHP_FUNCTION(array_fill) if (EXPECTED(num > 0)) { if (sizeof(num) > 4 && UNEXPECTED(EXPECTED(num > 0x7fffffff))) { - php_error_docref(NULL, E_WARNING, "Too many elements"); - RETURN_FALSE; + zend_throw_error(NULL, "Too many elements"); + return; } else if (UNEXPECTED(start_key > ZEND_LONG_MAX - num + 1)) { - php_error_docref(NULL, E_WARNING, "Cannot add element to the array as the next element is already occupied"); - RETURN_FALSE; + zend_throw_error(NULL, + "Cannot add element to the array as the next element is already occupied"); + return; } else if (EXPECTED(start_key >= 0) && EXPECTED(start_key < num)) { /* create packed array */ Bucket *p; @@ -2666,8 +2669,8 @@ PHP_FUNCTION(array_fill) } else if (EXPECTED(num == 0)) { RETURN_EMPTY_ARRAY(); } else { - php_error_docref(NULL, E_WARNING, "Number of elements can't be negative"); - RETURN_FALSE; + zend_throw_error(NULL, "Number of elements can't be negative"); + return; } } /* }}} */ @@ -2704,8 +2707,9 @@ PHP_FUNCTION(array_fill_keys) #define RANGE_CHECK_DOUBLE_INIT_ARRAY(start, end) do { \ double __calc_size = ((start - end) / step) + 1; \ if (__calc_size >= (double)HT_MAX_SIZE) { \ - php_error_docref(NULL, E_WARNING, "The supplied range exceeds the maximum array size: start=%0.0f end=%0.0f", end, start); \ - RETURN_FALSE; \ + zend_throw_error(NULL, \ + "The supplied range exceeds the maximum array size: start=%0.0f end=%0.0f", end, start); \ + return; \ } \ size = (uint32_t)_php_math_round(__calc_size, 0, PHP_ROUND_HALF_UP); \ array_init_size(return_value, size); \ @@ -2715,15 +2719,16 @@ PHP_FUNCTION(array_fill_keys) #define RANGE_CHECK_LONG_INIT_ARRAY(start, end) do { \ zend_ulong __calc_size = ((zend_ulong) start - end) / lstep; \ if (__calc_size >= HT_MAX_SIZE - 1) { \ - php_error_docref(NULL, E_WARNING, "The supplied range exceeds the maximum array size: start=" ZEND_LONG_FMT " end=" ZEND_LONG_FMT, end, start); \ - RETURN_FALSE; \ + zend_throw_error(NULL, \ + "The supplied range exceeds the maximum array size: start=" ZEND_LONG_FMT " end=" ZEND_LONG_FMT, end, start); \ + return; \ } \ size = (uint32_t)(__calc_size + 1); \ array_init_size(return_value, size); \ zend_hash_real_init_packed(Z_ARRVAL_P(return_value)); \ } while (0) -/* {{{ proto array|false range(mixed low, mixed high[, int step]) +/* {{{ proto array range(mixed low, mixed high[, int step]) Create an array containing the range of integers or characters from low to high (inclusive) */ PHP_FUNCTION(range) { @@ -2812,8 +2817,8 @@ PHP_FUNCTION(range) high = zval_get_double(zhigh); if (zend_isinf(high) || zend_isinf(low)) { - php_error_docref(NULL, E_WARNING, "Invalid range supplied: start=%0.0f end=%0.0f", low, high); - RETURN_FALSE; + zend_throw_error(NULL, "Invalid range supplied: start=%0.0f end=%0.0f", low, high); + return; } if (low > high) { /* Negative steps */ @@ -2905,8 +2910,8 @@ PHP_FUNCTION(range) } err: if (err) { - php_error_docref(NULL, E_WARNING, "step exceeds the specified range"); - RETURN_FALSE; + zend_throw_error(NULL, "step exceeds the specified range"); + return; } } /* }}} */ @@ -3146,7 +3151,7 @@ static void php_splice(HashTable *in_hash, zend_long offset, zend_long length, H } /* }}} */ -/* {{{ proto int|false array_push(array stack, mixed var [, mixed ...]) +/* {{{ proto int array_push(array stack, mixed var [, mixed ...]) Pushes elements onto the end of the array */ PHP_FUNCTION(array_push) { @@ -3168,8 +3173,9 @@ PHP_FUNCTION(array_push) if (zend_hash_next_index_insert(Z_ARRVAL_P(stack), &new_var) == NULL) { Z_TRY_DELREF(new_var); - php_error_docref(NULL, E_WARNING, "Cannot add element to the array as the next element is already occupied"); - RETURN_FALSE; + zend_throw_error(NULL, + "Cannot add element to the array as the next element is already occupied"); + return; } } @@ -3572,7 +3578,7 @@ PHPAPI int php_array_merge_recursive(HashTable *dest, HashTable *src) /* {{{ */ ZVAL_DEREF(dest_zval); thash = Z_TYPE_P(dest_zval) == IS_ARRAY ? Z_ARRVAL_P(dest_zval) : NULL; if ((thash && GC_IS_RECURSIVE(thash)) || (src_entry == dest_entry && Z_ISREF_P(dest_entry) && (Z_REFCOUNT_P(dest_entry) % 2))) { - php_error_docref(NULL, E_WARNING, "recursion detected"); + zend_throw_error(NULL, "Recursion detected"); return 0; } @@ -3693,7 +3699,7 @@ PHPAPI int php_array_replace_recursive(HashTable *dest, HashTable *src) /* {{{ * if (Z_IS_RECURSIVE_P(dest_zval) || Z_IS_RECURSIVE_P(src_zval) || (Z_ISREF_P(src_entry) && Z_ISREF_P(dest_entry) && Z_REF_P(src_entry) == Z_REF_P(dest_entry) && (Z_REFCOUNT_P(dest_entry) % 2))) { - php_error_docref(NULL, E_WARNING, "recursion detected"); + zend_throw_error(NULL, "Recursion detected"); return 0; } @@ -4101,7 +4107,8 @@ PHP_FUNCTION(array_count_values) Z_LVAL_P(tmp)++; } } else { - php_error_docref(NULL, E_WARNING, "Can only count STRING and INTEGER values!"); + zend_type_error("Can only count STRING and INTEGER values!"); + return; } } ZEND_HASH_FOREACH_END(); } @@ -4129,7 +4136,7 @@ zend_bool array_column_param_helper(zval *param, return 1; default: - php_error_docref(NULL, E_WARNING, "The %s key should be either a string or an integer", name); + zend_type_error("The %s key should be either a string or an integer", name); return 0; } } @@ -4323,7 +4330,7 @@ PHP_FUNCTION(array_reverse) } /* }}} */ -/* {{{ proto array|false array_pad(array input, int pad_size, mixed pad_value) +/* {{{ proto array array_pad(array input, int pad_size, mixed pad_value) Returns a copy of input array padded with pad_value to size pad_size */ PHP_FUNCTION(array_pad) { @@ -4347,8 +4354,8 @@ PHP_FUNCTION(array_pad) input_size = zend_hash_num_elements(Z_ARRVAL_P(input)); pad_size_abs = ZEND_ABS(pad_size); if (pad_size_abs < 0 || pad_size_abs - input_size > Z_L(1048576)) { - php_error_docref(NULL, E_WARNING, "You may only pad up to 1048576 elements at a time"); - RETURN_FALSE; + zend_throw_error(NULL, "Only 1048576 elements may be pad up at a time."); + return; } if (input_size >= pad_size_abs) { @@ -4444,7 +4451,8 @@ PHP_FUNCTION(array_flip) } zend_symtable_update(Z_ARRVAL_P(return_value), Z_STR_P(entry), &data); } else { - php_error_docref(NULL, E_WARNING, "Can only flip STRING and INTEGER values!"); + zend_type_error("Can only flip STRING and INTEGER values!"); + return; } } ZEND_HASH_FOREACH_END(); } @@ -5174,7 +5182,8 @@ static void php_array_diff(INTERNAL_FUNCTION_PARAMETERS, int behavior, int data_ param_spec = "+f"; diff_data_compare_func = php_array_user_compare; } else { - php_error_docref(NULL, E_WARNING, "data_compare_type is %d. This should never happen. Please report as a bug", data_compare_type); + zend_throw_error(NULL, + "data_compare_type is %d. This should never happen. Please report as a bug", data_compare_type); return; } @@ -5688,7 +5697,7 @@ PHP_FUNCTION(array_multisort) sort_order = Z_LVAL_P(arg) == PHP_SORT_DESC ? PHP_SORT_DESC : PHP_SORT_ASC; parse_state[MULTISORT_ORDER] = 0; } else { - php_error_docref(NULL, E_WARNING, "Argument #%d is expected to be an array or sorting flag that has not already been specified", i + 1); + zend_type_error("Argument #%d is expected to be an array or sorting flag that has not already been specified", i + 1); MULTISORT_ABORT; } break; @@ -5704,19 +5713,19 @@ PHP_FUNCTION(array_multisort) sort_type = (int)Z_LVAL_P(arg); parse_state[MULTISORT_TYPE] = 0; } else { - php_error_docref(NULL, E_WARNING, "Argument #%d is expected to be an array or sorting flag that has not already been specified", i + 1); + zend_type_error("Argument #%d is expected to be an array or sorting flag that has not already been specified", i + 1); MULTISORT_ABORT; } break; default: - php_error_docref(NULL, E_WARNING, "Argument #%d is an unknown sort flag", i + 1); + zend_type_error("Argument #%d is an unknown sort flag", i + 1); MULTISORT_ABORT; break; } } else { - php_error_docref(NULL, E_WARNING, "Argument #%d is expected to be an array or a sort flag", i + 1); + zend_type_error("Argument #%d is expected to be an array or a sort flag", i + 1); MULTISORT_ABORT; } } @@ -5727,7 +5736,7 @@ PHP_FUNCTION(array_multisort) array_size = zend_hash_num_elements(Z_ARRVAL_P(arrays[0])); for (i = 0; i < num_arrays; i++) { if (zend_hash_num_elements(Z_ARRVAL_P(arrays[i])) != (uint32_t)array_size) { - php_error_docref(NULL, E_WARNING, "Array sizes are inconsistent"); + zend_throw_error(NULL, "Array sizes are inconsistent"); MULTISORT_ABORT; } } @@ -5823,7 +5832,7 @@ PHP_FUNCTION(array_rand) num_avail = zend_hash_num_elements(Z_ARRVAL_P(input)); if (num_avail == 0) { - php_error_docref(NULL, E_WARNING, "Array is empty"); + zend_throw_error(NULL, "Array is empty"); return; } @@ -5864,7 +5873,8 @@ PHP_FUNCTION(array_rand) } if (num_req <= 0 || num_req > num_avail) { - php_error_docref(NULL, E_WARNING, "Second argument has to be between 1 and the number of elements in the array"); + zend_throw_error(NULL, + "Second argument has to be between 1 and the number of elements in the array"); return; } @@ -6322,8 +6332,8 @@ PHP_FUNCTION(array_key_exists) RETVAL_BOOL(zend_hash_exists_ind(ht, ZSTR_EMPTY_ALLOC())); break; default: - php_error_docref(NULL, E_WARNING, "The first argument should be either a string or an integer"); - RETVAL_FALSE; + zend_type_error("The first argument should be either a string or an integer"); + return; } if (Z_TYPE_P(array) != IS_ARRAY) { @@ -6354,7 +6364,7 @@ PHP_FUNCTION(array_chunk) /* Do bounds checking for size parameter. */ if (size < 1) { - php_error_docref(NULL, E_WARNING, "Size parameter expected to be greater than 0"); + zend_throw_error(NULL, "Size parameter expected to be greater than 0"); return; } @@ -6401,7 +6411,7 @@ PHP_FUNCTION(array_chunk) } /* }}} */ -/* {{{ proto array|false array_combine(array keys, array values) +/* {{{ proto array array_combine(array keys, array values) Creates an array by using the elements of the first parameter as keys and the elements of the second as the corresponding values */ PHP_FUNCTION(array_combine) { @@ -6419,8 +6429,8 @@ PHP_FUNCTION(array_combine) num_values = zend_hash_num_elements(values); if (num_keys != num_values) { - php_error_docref(NULL, E_WARNING, "Both parameters should have an equal number of elements"); - RETURN_FALSE; + zend_throw_error(NULL, "Both parameters should have an equal number of elements"); + return; } if (!num_keys) { diff --git a/ext/standard/tests/array/array_chunk.phpt b/ext/standard/tests/array/array_chunk.phpt deleted file mode 100644 index 2ee77e129ca0d..0000000000000 --- a/ext/standard/tests/array/array_chunk.phpt +++ /dev/null @@ -1,21 +0,0 @@ ---TEST-- -array_chunk() ---FILE-- - ---EXPECT-- -array(0) { -} -[0] -NULL -NULL -NULL diff --git a/ext/standard/tests/array/array_chunk2.phpt b/ext/standard/tests/array/array_chunk2.phpt index 6d8b74545e483..c02194aa5b998 100644 --- a/ext/standard/tests/array/array_chunk2.phpt +++ b/ext/standard/tests/array/array_chunk2.phpt @@ -3,8 +3,19 @@ basic array_chunk test --FILE-- getMessage() . "\n"; +} + +try { + var_dump(array_chunk($input_array, 0, true)); +} catch (\Error $e) { + echo $e->getMessage() . "\n"; +} + var_dump(array_chunk($input_array, 1)); var_dump(array_chunk($input_array, 1, true)); var_dump(array_chunk($input_array, 2)); @@ -12,12 +23,9 @@ var_dump(array_chunk($input_array, 2, true)); var_dump(array_chunk($input_array, 10)); var_dump(array_chunk($input_array, 10, true)); ?> ---EXPECTF-- -Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d -NULL - -Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d -NULL +--EXPECT-- +Size parameter expected to be greater than 0 +Size parameter expected to be greater than 0 array(5) { [0]=> array(1) { diff --git a/ext/standard/tests/array/array_chunk_variation10.phpt b/ext/standard/tests/array/array_chunk_variation10.phpt index 7b4bee172beb2..be5fcdc7f30a7 100644 --- a/ext/standard/tests/array/array_chunk_variation10.phpt +++ b/ext/standard/tests/array/array_chunk_variation10.phpt @@ -4,11 +4,11 @@ array_chunk() - variation 10 1, 2 => 2, 3 => 3); var_dump ($array); -for ($i = 0; $i < (sizeof($array) + 1); $i++) { +for ($i = 1; $i < (sizeof($array) + 1); $i++) { echo "[$i]\n"; - var_dump (@array_chunk ($array, $i)); - var_dump (@array_chunk ($array, $i, TRUE)); - var_dump (@array_chunk ($array, $i, FALSE)); + var_dump (array_chunk ($array, $i)); + var_dump (array_chunk ($array, $i, TRUE)); + var_dump (array_chunk ($array, $i, FALSE)); echo "\n"; } ?> @@ -21,11 +21,6 @@ array(3) { [3]=> int(3) } -[0] -NULL -NULL -NULL - [1] array(3) { [0]=> diff --git a/ext/standard/tests/array/array_chunk_variation11.phpt b/ext/standard/tests/array/array_chunk_variation11.phpt index dca366652d919..09ec255744252 100644 --- a/ext/standard/tests/array/array_chunk_variation11.phpt +++ b/ext/standard/tests/array/array_chunk_variation11.phpt @@ -5,11 +5,11 @@ array_chunk() - variation 11 $array = array (0 => 0, 3 => 2); var_dump ($array); -for ($i = 0; $i < (sizeof($array) + 1); $i++) { +for ($i = 1; $i < (sizeof($array) + 1); $i++) { echo "[$i]\n"; - var_dump (@array_chunk ($array, $i)); - var_dump (@array_chunk ($array, $i, TRUE)); - var_dump (@array_chunk ($array, $i, FALSE)); + var_dump (array_chunk ($array, $i)); + var_dump (array_chunk ($array, $i, TRUE)); + var_dump (array_chunk ($array, $i, FALSE)); echo "\n"; } ?> @@ -20,11 +20,6 @@ array(2) { [3]=> int(2) } -[0] -NULL -NULL -NULL - [1] array(2) { [0]=> diff --git a/ext/standard/tests/array/array_chunk_variation12.phpt b/ext/standard/tests/array/array_chunk_variation12.phpt index 3b87dbab95028..f85f2a8c0dc59 100644 --- a/ext/standard/tests/array/array_chunk_variation12.phpt +++ b/ext/standard/tests/array/array_chunk_variation12.phpt @@ -4,11 +4,11 @@ array_chunk() - variation 12 1, 5 => 2, 8 => 3); var_dump ($array); -for ($i = 0; $i < (sizeof($array) + 1); $i++) { +for ($i = 1; $i < (sizeof($array) + 1); $i++) { echo "[$i]\n"; - var_dump (@array_chunk ($array, $i)); - var_dump (@array_chunk ($array, $i, TRUE)); - var_dump (@array_chunk ($array, $i, FALSE)); + var_dump (array_chunk ($array, $i)); + var_dump (array_chunk ($array, $i, TRUE)); + var_dump (array_chunk ($array, $i, FALSE)); echo "\n"; } ?> @@ -21,11 +21,6 @@ array(3) { [8]=> int(3) } -[0] -NULL -NULL -NULL - [1] array(3) { [0]=> diff --git a/ext/standard/tests/array/array_chunk_variation13.phpt b/ext/standard/tests/array/array_chunk_variation13.phpt index f6369df1c8a1d..5cd6f0ea34fae 100644 --- a/ext/standard/tests/array/array_chunk_variation13.phpt +++ b/ext/standard/tests/array/array_chunk_variation13.phpt @@ -4,11 +4,11 @@ array_chunk() - variation 13 @@ -19,11 +19,6 @@ array(2) { [1]=> int(2) } -[0] -NULL -NULL -NULL - [1] array(2) { [0]=> diff --git a/ext/standard/tests/array/array_chunk_variation14.phpt b/ext/standard/tests/array/array_chunk_variation14.phpt index f8d1b11790f17..97fce1e7224e3 100644 --- a/ext/standard/tests/array/array_chunk_variation14.phpt +++ b/ext/standard/tests/array/array_chunk_variation14.phpt @@ -4,11 +4,11 @@ array_chunk() - variation 14 @@ -21,11 +21,6 @@ array(3) { [2]=> int(2) } -[0] -NULL -NULL -NULL - [1] array(3) { [0]=> diff --git a/ext/standard/tests/array/array_chunk_variation15.phpt b/ext/standard/tests/array/array_chunk_variation15.phpt index abec754a3d3af..c48af63f6ced6 100644 --- a/ext/standard/tests/array/array_chunk_variation15.phpt +++ b/ext/standard/tests/array/array_chunk_variation15.phpt @@ -4,11 +4,11 @@ array_chunk() - variation 15 @@ -21,11 +21,6 @@ array(3) { [2]=> int(3) } -[0] -NULL -NULL -NULL - [1] array(3) { [0]=> diff --git a/ext/standard/tests/array/array_chunk_variation16.phpt b/ext/standard/tests/array/array_chunk_variation16.phpt index 18179c8b07b92..3426f9278bfcb 100644 --- a/ext/standard/tests/array/array_chunk_variation16.phpt +++ b/ext/standard/tests/array/array_chunk_variation16.phpt @@ -4,11 +4,11 @@ array_chunk() - variation 16 @@ -23,11 +23,6 @@ array(4) { [3]=> int(3) } -[0] -NULL -NULL -NULL - [1] array(4) { [0]=> diff --git a/ext/standard/tests/array/array_chunk_variation17.phpt b/ext/standard/tests/array/array_chunk_variation17.phpt index 27507ea8cd5e4..1a8bb5d34014a 100644 --- a/ext/standard/tests/array/array_chunk_variation17.phpt +++ b/ext/standard/tests/array/array_chunk_variation17.phpt @@ -4,11 +4,11 @@ array_chunk() - variation 17 @@ -23,11 +23,6 @@ array(4) { [3]=> int(4) } -[0] -NULL -NULL -NULL - [1] array(4) { [0]=> diff --git a/ext/standard/tests/array/array_chunk_variation18.phpt b/ext/standard/tests/array/array_chunk_variation18.phpt index 7f0946f4977ee..593c702ce94d1 100644 --- a/ext/standard/tests/array/array_chunk_variation18.phpt +++ b/ext/standard/tests/array/array_chunk_variation18.phpt @@ -4,11 +4,11 @@ array_chunk() - variation 18 @@ -25,11 +25,6 @@ array(5) { [4]=> int(4) } -[0] -NULL -NULL -NULL - [1] array(5) { [0]=> diff --git a/ext/standard/tests/array/array_chunk_variation19.phpt b/ext/standard/tests/array/array_chunk_variation19.phpt index d51389c9f3b6a..f160cba2631f7 100644 --- a/ext/standard/tests/array/array_chunk_variation19.phpt +++ b/ext/standard/tests/array/array_chunk_variation19.phpt @@ -4,11 +4,11 @@ array_chunk() - variation 19 @@ -35,11 +35,6 @@ array(10) { [9]=> int(10) } -[0] -NULL -NULL -NULL - [1] array(10) { [0]=> diff --git a/ext/standard/tests/array/array_chunk_variation20.phpt b/ext/standard/tests/array/array_chunk_variation20.phpt index cd5314ff04c3c..d47279915c9fa 100644 --- a/ext/standard/tests/array/array_chunk_variation20.phpt +++ b/ext/standard/tests/array/array_chunk_variation20.phpt @@ -4,11 +4,11 @@ array_chunk() - variation 20 @@ -37,11 +37,6 @@ array(11) { [10]=> int(10) } -[0] -NULL -NULL -NULL - [1] array(11) { [0]=> diff --git a/ext/standard/tests/array/array_chunk_variation21.phpt b/ext/standard/tests/array/array_chunk_variation21.phpt index 678bf16751c0f..e8c7784325a4e 100644 --- a/ext/standard/tests/array/array_chunk_variation21.phpt +++ b/ext/standard/tests/array/array_chunk_variation21.phpt @@ -4,11 +4,11 @@ array_chunk() - variation 21 1); var_dump ($array); -for ($i = 0; $i < (sizeof($array) + 1); $i++) { +for ($i = 1; $i < (sizeof($array) + 1); $i++) { echo "[$i]\n"; - var_dump (@array_chunk ($array, $i)); - var_dump (@array_chunk ($array, $i, TRUE)); - var_dump (@array_chunk ($array, $i, FALSE)); + var_dump (array_chunk ($array, $i)); + var_dump (array_chunk ($array, $i, TRUE)); + var_dump (array_chunk ($array, $i, FALSE)); echo "\n"; } ?> @@ -17,11 +17,6 @@ array(1) { ["a"]=> int(1) } -[0] -NULL -NULL -NULL - [1] array(1) { [0]=> diff --git a/ext/standard/tests/array/array_chunk_variation22.phpt b/ext/standard/tests/array/array_chunk_variation22.phpt index 45c458ebf95e3..b0eeade3ab00b 100644 --- a/ext/standard/tests/array/array_chunk_variation22.phpt +++ b/ext/standard/tests/array/array_chunk_variation22.phpt @@ -4,11 +4,11 @@ array_chunk() - variation 22 1, "c" => 2); var_dump ($array); -for ($i = 0; $i < (sizeof($array) + 1); $i++) { +for ($i = 1; $i < (sizeof($array) + 1); $i++) { echo "[$i]\n"; - var_dump (@array_chunk ($array, $i)); - var_dump (@array_chunk ($array, $i, TRUE)); - var_dump (@array_chunk ($array, $i, FALSE)); + var_dump (array_chunk ($array, $i)); + var_dump (array_chunk ($array, $i, TRUE)); + var_dump (array_chunk ($array, $i, FALSE)); echo "\n"; } ?> @@ -19,11 +19,6 @@ array(2) { ["c"]=> int(2) } -[0] -NULL -NULL -NULL - [1] array(2) { [0]=> diff --git a/ext/standard/tests/array/array_chunk_variation23.phpt b/ext/standard/tests/array/array_chunk_variation23.phpt index 80b92985b15f3..87ced15132074 100644 --- a/ext/standard/tests/array/array_chunk_variation23.phpt +++ b/ext/standard/tests/array/array_chunk_variation23.phpt @@ -4,11 +4,11 @@ array_chunk() - variation 23 1, "q" => 2, "r" => 3, "s" => 4, "u" => 5, "v" => 6); var_dump ($array); -for ($i = 0; $i < (sizeof($array) + 1); $i++) { +for ($i = 1; $i < (sizeof($array) + 1); $i++) { echo "[$i]\n"; - var_dump (@array_chunk ($array, $i)); - var_dump (@array_chunk ($array, $i, TRUE)); - var_dump (@array_chunk ($array, $i, FALSE)); + var_dump (array_chunk ($array, $i)); + var_dump (array_chunk ($array, $i, TRUE)); + var_dump (array_chunk ($array, $i, FALSE)); echo "\n"; } ?> @@ -27,11 +27,6 @@ array(6) { ["v"]=> int(6) } -[0] -NULL -NULL -NULL - [1] array(6) { [0]=> diff --git a/ext/standard/tests/array/array_chunk_variation24.phpt b/ext/standard/tests/array/array_chunk_variation24.phpt index e25f53f6b6564..69dce7be17465 100644 --- a/ext/standard/tests/array/array_chunk_variation24.phpt +++ b/ext/standard/tests/array/array_chunk_variation24.phpt @@ -4,11 +4,11 @@ array_chunk() - variation 24 "A"); var_dump ($array); -for ($i = 0; $i < (sizeof($array) + 1); $i++) { +for ($i = 1; $i < (sizeof($array) + 1); $i++) { echo "[$i]\n"; - var_dump (@array_chunk ($array, $i)); - var_dump (@array_chunk ($array, $i, TRUE)); - var_dump (@array_chunk ($array, $i, FALSE)); + var_dump (array_chunk ($array, $i)); + var_dump (array_chunk ($array, $i, TRUE)); + var_dump (array_chunk ($array, $i, FALSE)); echo "\n"; } ?> @@ -17,11 +17,6 @@ array(1) { ["a"]=> string(1) "A" } -[0] -NULL -NULL -NULL - [1] array(1) { [0]=> diff --git a/ext/standard/tests/array/array_chunk_variation25.phpt b/ext/standard/tests/array/array_chunk_variation25.phpt index eae89e952b115..09303c30ba758 100644 --- a/ext/standard/tests/array/array_chunk_variation25.phpt +++ b/ext/standard/tests/array/array_chunk_variation25.phpt @@ -4,11 +4,11 @@ array_chunk() - variation 25 "A", "q" => "B", "r" => "C", "s" => "D", "u" => "E", "v" => "F"); var_dump ($array); -for ($i = 0; $i < (sizeof($array) + 1); $i++) { +for ($i = 1; $i < (sizeof($array) + 1); $i++) { echo "[$i]\n"; - var_dump (@array_chunk ($array, $i)); - var_dump (@array_chunk ($array, $i, TRUE)); - var_dump (@array_chunk ($array, $i, FALSE)); + var_dump (array_chunk ($array, $i)); + var_dump (array_chunk ($array, $i, TRUE)); + var_dump (array_chunk ($array, $i, FALSE)); echo "\n"; } ?> @@ -27,11 +27,6 @@ array(6) { ["v"]=> string(1) "F" } -[0] -NULL -NULL -NULL - [1] array(6) { [0]=> diff --git a/ext/standard/tests/array/array_chunk_variation26.phpt b/ext/standard/tests/array/array_chunk_variation26.phpt index 487f6b4f67622..ca6975a64e9c6 100644 --- a/ext/standard/tests/array/array_chunk_variation26.phpt +++ b/ext/standard/tests/array/array_chunk_variation26.phpt @@ -4,11 +4,11 @@ array_chunk() - variation 26 @@ -17,11 +17,6 @@ array(1) { [0]=> int(0) } -[0] -NULL -NULL -NULL - [1] array(1) { [0]=> diff --git a/ext/standard/tests/array/array_chunk_variation27.phpt b/ext/standard/tests/array/array_chunk_variation27.phpt index a83a16b7fbdde..aa91036a52064 100644 --- a/ext/standard/tests/array/array_chunk_variation27.phpt +++ b/ext/standard/tests/array/array_chunk_variation27.phpt @@ -4,11 +4,11 @@ array_chunk() - variation 27 @@ -17,11 +17,6 @@ array(1) { [0]=> int(1) } -[0] -NULL -NULL -NULL - [1] array(1) { [0]=> diff --git a/ext/standard/tests/array/array_chunk_variation28.phpt b/ext/standard/tests/array/array_chunk_variation28.phpt index bdbaf45cbd52d..5389049ce40ad 100644 --- a/ext/standard/tests/array/array_chunk_variation28.phpt +++ b/ext/standard/tests/array/array_chunk_variation28.phpt @@ -4,11 +4,11 @@ array_chunk() - variation 28 @@ -17,11 +17,6 @@ array(1) { [0]=> int(-1) } -[0] -NULL -NULL -NULL - [1] array(1) { [0]=> diff --git a/ext/standard/tests/array/array_chunk_variation29.phpt b/ext/standard/tests/array/array_chunk_variation29.phpt index 12f50c11906b2..f18de5ea8577c 100644 --- a/ext/standard/tests/array/array_chunk_variation29.phpt +++ b/ext/standard/tests/array/array_chunk_variation29.phpt @@ -4,11 +4,11 @@ array_chunk() - variation 29 @@ -19,11 +19,6 @@ array(2) { [1]=> int(2) } -[0] -NULL -NULL -NULL - [1] array(2) { [0]=> diff --git a/ext/standard/tests/array/array_chunk_variation30.phpt b/ext/standard/tests/array/array_chunk_variation30.phpt index 281537a876069..0dbd9b63683fb 100644 --- a/ext/standard/tests/array/array_chunk_variation30.phpt +++ b/ext/standard/tests/array/array_chunk_variation30.phpt @@ -4,11 +4,11 @@ array_chunk() - variation 30 @@ -21,11 +21,6 @@ array(3) { [2]=> int(3) } -[0] -NULL -NULL -NULL - [1] array(3) { [0]=> diff --git a/ext/standard/tests/array/array_chunk_variation31.phpt b/ext/standard/tests/array/array_chunk_variation31.phpt index 1592679839d5e..fd7f358ca0ddb 100644 --- a/ext/standard/tests/array/array_chunk_variation31.phpt +++ b/ext/standard/tests/array/array_chunk_variation31.phpt @@ -4,11 +4,11 @@ array_chunk() - variation 31 0); var_dump ($array); -for ($i = 0; $i < (sizeof($array) + 1); $i++) { +for ($i = 1; $i < (sizeof($array) + 1); $i++) { echo "[$i]\n"; - var_dump (@array_chunk ($array, $i)); - var_dump (@array_chunk ($array, $i, TRUE)); - var_dump (@array_chunk ($array, $i, FALSE)); + var_dump (array_chunk ($array, $i)); + var_dump (array_chunk ($array, $i, TRUE)); + var_dump (array_chunk ($array, $i, FALSE)); echo "\n"; } ?> @@ -17,11 +17,6 @@ array(1) { [1]=> int(0) } -[0] -NULL -NULL -NULL - [1] array(1) { [0]=> diff --git a/ext/standard/tests/array/array_chunk_variation32.phpt b/ext/standard/tests/array/array_chunk_variation32.phpt index cf65993c0b692..09471a59aaf43 100644 --- a/ext/standard/tests/array/array_chunk_variation32.phpt +++ b/ext/standard/tests/array/array_chunk_variation32.phpt @@ -4,11 +4,11 @@ array_chunk() - variation 32 1); var_dump ($array); -for ($i = 0; $i < (sizeof($array) + 1); $i++) { +for ($i = 1; $i < (sizeof($array) + 1); $i++) { echo "[$i]\n"; - var_dump (@array_chunk ($array, $i)); - var_dump (@array_chunk ($array, $i, TRUE)); - var_dump (@array_chunk ($array, $i, FALSE)); + var_dump (array_chunk ($array, $i)); + var_dump (array_chunk ($array, $i, TRUE)); + var_dump (array_chunk ($array, $i, FALSE)); echo "\n"; } ?> @@ -17,11 +17,6 @@ array(1) { [2]=> int(1) } -[0] -NULL -NULL -NULL - [1] array(1) { [0]=> diff --git a/ext/standard/tests/array/array_chunk_variation5.phpt b/ext/standard/tests/array/array_chunk_variation5.phpt index 50050892e7067..21f1a3dce286a 100644 --- a/ext/standard/tests/array/array_chunk_variation5.phpt +++ b/ext/standard/tests/array/array_chunk_variation5.phpt @@ -26,26 +26,33 @@ $sizes = array(-1, count($input_array) + 1, 0, 1.5); // loop through the array for size argument foreach ($sizes as $size){ - echo "\n-- Testing array_chunk() when size = $size --\n"; - var_dump( array_chunk($input_array, $size) ); - var_dump( array_chunk($input_array, $size, true) ); - var_dump( array_chunk($input_array, $size, false) ); + echo "\n-- Testing array_chunk() when size = $size --\n"; + try { + var_dump( array_chunk($input_array, $size) ); + } catch (\Error $e) { + echo $e->getMessage() . "\n"; + } + try { + var_dump( array_chunk($input_array, $size, true) ); + } catch (\Error $e) { + echo $e->getMessage() . "\n"; + } + try { + var_dump( array_chunk($input_array, $size, false) ); + } catch (\Error $e) { + echo $e->getMessage() . "\n"; + } } -echo "Done"; ?> ---EXPECTF-- + +DONE +--EXPECT-- *** Testing array_chunk() : usage variations *** -- Testing array_chunk() when size = -1 -- - -Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d -NULL - -Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d -NULL - -Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d -NULL +Size parameter expected to be greater than 0 +Size parameter expected to be greater than 0 +Size parameter expected to be greater than 0 -- Testing array_chunk() when size = 4 -- array(1) { @@ -83,15 +90,9 @@ array(1) { } -- Testing array_chunk() when size = 0 -- - -Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d -NULL - -Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d -NULL - -Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d -NULL +Size parameter expected to be greater than 0 +Size parameter expected to be greater than 0 +Size parameter expected to be greater than 0 -- Testing array_chunk() when size = 1.5 -- array(3) { @@ -145,4 +146,5 @@ array(3) { int(3) } } -Done + +DONE diff --git a/ext/standard/tests/array/array_chunk_variation8.phpt b/ext/standard/tests/array/array_chunk_variation8.phpt index 6a6e752ecb9ed..64b9bb2036177 100644 --- a/ext/standard/tests/array/array_chunk_variation8.phpt +++ b/ext/standard/tests/array/array_chunk_variation8.phpt @@ -4,11 +4,11 @@ array_chunk() - variation 8 -1); var_dump ($array); -for ($i = 0; $i < (sizeof($array) + 1); $i++) { +for ($i = 1; $i < (sizeof($array) + 1); $i++) { echo "[$i]\n"; - var_dump (@array_chunk ($array, $i)); - var_dump (@array_chunk ($array, $i, TRUE)); - var_dump (@array_chunk ($array, $i, FALSE)); + var_dump (array_chunk ($array, $i)); + var_dump (array_chunk ($array, $i, TRUE)); + var_dump (array_chunk ($array, $i, FALSE)); echo "\n"; } ?> @@ -17,11 +17,6 @@ array(1) { [3]=> int(-1) } -[0] -NULL -NULL -NULL - [1] array(1) { [0]=> diff --git a/ext/standard/tests/array/array_chunk_variation9.phpt b/ext/standard/tests/array/array_chunk_variation9.phpt index ec57da4f88c07..a68240e6f6425 100644 --- a/ext/standard/tests/array/array_chunk_variation9.phpt +++ b/ext/standard/tests/array/array_chunk_variation9.phpt @@ -4,11 +4,11 @@ array_chunk() - variation 9 0, 2 => 2); var_dump ($array); -for ($i = 0; $i < (sizeof($array) + 1); $i++) { +for ($i = 1; $i < (sizeof($array) + 1); $i++) { echo "[$i]\n"; - var_dump (@array_chunk ($array, $i)); - var_dump (@array_chunk ($array, $i, TRUE)); - var_dump (@array_chunk ($array, $i, FALSE)); + var_dump (array_chunk ($array, $i)); + var_dump (array_chunk ($array, $i, TRUE)); + var_dump (array_chunk ($array, $i, FALSE)); echo "\n"; } ?> @@ -19,11 +19,6 @@ array(2) { [2]=> int(2) } -[0] -NULL -NULL -NULL - [1] array(2) { [0]=> diff --git a/ext/standard/tests/array/array_column_error.phpt b/ext/standard/tests/array/array_column_error.phpt index 92232485202f8..6fb5169d454bd 100644 --- a/ext/standard/tests/array/array_column_error.phpt +++ b/ext/standard/tests/array/array_column_error.phpt @@ -10,41 +10,51 @@ Test array_column() function: error conditions */ echo "*** Testing array_column() : error conditions ***\n"; - echo "\n-- Testing array_column() column key parameter should be a string or an integer (testing bool) --\n"; -var_dump(array_column(array(), true)); +try { + var_dump(array_column(array(), true)); +} catch (\TypeError $e) { + echo $e->getMessage() . "\n"; +} + echo "\n-- Testing array_column() column key parameter should be a string or integer (testing array) --\n"; -var_dump(array_column(array(), array())); +try { + var_dump(array_column(array(), array())); +} catch (\TypeError $e) { + echo $e->getMessage() . "\n"; +} echo "\n-- Testing array_column() index key parameter should be a string or an integer (testing bool) --\n"; -var_dump(array_column(array(), 'foo', true)); +try { + var_dump(array_column(array(), 'foo', true)); +} catch (\TypeError $e) { + echo $e->getMessage() . "\n"; +} echo "\n-- Testing array_column() index key parameter should be a string or integer (testing array) --\n"; -var_dump(array_column(array(), 'foo', array())); +try { + var_dump(array_column(array(), 'foo', array())); +} catch (\TypeError $e) { + echo $e->getMessage() . "\n"; +} -echo "Done\n"; ?> ---EXPECTF-- + +DONE +--EXPECT-- *** Testing array_column() : error conditions *** -- Testing array_column() column key parameter should be a string or an integer (testing bool) -- - -Warning: array_column(): The column key should be either a string or an integer in %s on line %d -bool(false) +The column key should be either a string or an integer -- Testing array_column() column key parameter should be a string or integer (testing array) -- - -Warning: array_column(): The column key should be either a string or an integer in %s on line %d -bool(false) +The column key should be either a string or an integer -- Testing array_column() index key parameter should be a string or an integer (testing bool) -- - -Warning: array_column(): The index key should be either a string or an integer in %s on line %d -bool(false) +The index key should be either a string or an integer -- Testing array_column() index key parameter should be a string or integer (testing array) -- +The index key should be either a string or an integer -Warning: array_column(): The index key should be either a string or an integer in %s on line %d -bool(false) -Done +DONE diff --git a/ext/standard/tests/array/array_combine_error2.phpt b/ext/standard/tests/array/array_combine_error2.phpt index 2d820a0d2182e..463dc6dfe812a 100644 --- a/ext/standard/tests/array/array_combine_error2.phpt +++ b/ext/standard/tests/array/array_combine_error2.phpt @@ -16,19 +16,32 @@ var_dump( array_combine(array(), array()) ); // Testing array_combine by passing empty array to $keys echo "\n-- Testing array_combine() function with empty array for \$keys argument --\n"; -var_dump( array_combine(array(), array(1, 2)) ); +try { + var_dump( array_combine(array(), array(1, 2)) ); +} catch (\Error $e) { + echo $e->getMessage(); +} // Testing array_combine by passing empty array to $values echo "\n-- Testing array_combine() function with empty array for \$values argument --\n"; -var_dump( array_combine(array(1, 2), array()) ); +try { + var_dump( array_combine(array(1, 2), array()) ); +} catch (\Error $e) { + echo $e->getMessage(); +} // Testing array_combine with arrays having unequal number of elements echo "\n-- Testing array_combine() function by passing array with unequal number of elements --\n"; -var_dump( array_combine(array(1, 2), array(1, 2, 3)) ); +try { + var_dump( array_combine(array(1, 2), array(1, 2, 3)) ); +} catch (\Error $e) { + echo $e->getMessage(); +} -echo "Done"; ?> ---EXPECTF-- + +DONE +--EXPECT-- *** Testing array_combine() : error conditions specific to array_combine() *** -- Testing array_combine() function with empty arrays -- @@ -36,17 +49,9 @@ array(0) { } -- Testing array_combine() function with empty array for $keys argument -- - -Warning: array_combine(): Both parameters should have an equal number of elements in %s on line %d -bool(false) - +Both parameters should have an equal number of elements -- Testing array_combine() function with empty array for $values argument -- - -Warning: array_combine(): Both parameters should have an equal number of elements in %s on line %d -bool(false) - +Both parameters should have an equal number of elements -- Testing array_combine() function by passing array with unequal number of elements -- - -Warning: array_combine(): Both parameters should have an equal number of elements in %s on line %d -bool(false) -Done +Both parameters should have an equal number of elements +DONE diff --git a/ext/standard/tests/array/array_count_values.phpt b/ext/standard/tests/array/array_count_values.phpt index a6424aab9a6aa..fe041640e9dd4 100644 --- a/ext/standard/tests/array/array_count_values.phpt +++ b/ext/standard/tests/array/array_count_values.phpt @@ -18,7 +18,11 @@ $arrays = array ( ); foreach ($arrays as $item) { - var_dump (@array_count_values ($item)); + try { + var_dump (array_count_values ($item)); + } catch (\TypeError $e) { + echo $e->getMessage() . "\n"; + } echo "\n"; } ?> @@ -83,12 +87,6 @@ array(3) { int(4) } -array(1) { - [0]=> - int(1) -} +Can only count STRING and INTEGER values! -array(1) { - [1]=> - int(1) -} +Can only count STRING and INTEGER values! diff --git a/ext/standard/tests/array/array_count_values2.phpt b/ext/standard/tests/array/array_count_values2.phpt index 8aaf445f932ca..edce8142e2894 100644 --- a/ext/standard/tests/array/array_count_values2.phpt +++ b/ext/standard/tests/array/array_count_values2.phpt @@ -15,29 +15,12 @@ $array1 = array(1, FALSE, NULL, 0); -var_dump(array_count_values($array1)); -?> ---EXPECTF-- -Warning: array_count_values(): Can only count STRING and INTEGER values! in %s on line %d - -Warning: array_count_values(): Can only count STRING and INTEGER values! in %s on line %d -Warning: array_count_values(): Can only count STRING and INTEGER values! in %s on line %d -array(8) { - [1]=> - int(2) - ["hello"]=> - int(2) - ["world"]=> - int(1) - [""]=> - int(1) - ["rabbit"]=> - int(1) - ["foo"]=> - int(1) - ["Foo"]=> - int(1) - [0]=> - int(1) +try { + var_dump(array_count_values($array1)); +} catch (\TypeError $e) { + echo $e->getMessage() . "\n"; } +?> +--EXPECT-- +Can only count STRING and INTEGER values! diff --git a/ext/standard/tests/array/array_count_values_variation.phpt b/ext/standard/tests/array/array_count_values_variation.phpt index 00f13c8a5b7a9..d9eaa6c6c15a0 100644 --- a/ext/standard/tests/array/array_count_values_variation.phpt +++ b/ext/standard/tests/array/array_count_values_variation.phpt @@ -26,25 +26,21 @@ $fp = fopen("array_count_file", "w+"); $arrays = array ("bobk" => "bobv", "val", 6 => "val6", $fp, $ob); -var_dump (@array_count_values ($arrays)); -echo "\n"; - +try { + var_dump (array_count_values ($arrays)); +} catch (\TypeError $e) { + echo $e->getMessage() . "\n"; +} -echo "Done"; ?> + +DONE --CLEAN-- --EXPECT-- *** Testing array_count_values() : parameter variations *** -array(3) { - ["bobv"]=> - int(1) - ["val"]=> - int(1) - ["val6"]=> - int(1) -} +Can only count STRING and INTEGER values! -Done +DONE diff --git a/ext/standard/tests/array/array_fill_error.phpt b/ext/standard/tests/array/array_fill_error.phpt index 386404a33629e..63af88bf284ac 100644 --- a/ext/standard/tests/array/array_fill_error.phpt +++ b/ext/standard/tests/array/array_fill_error.phpt @@ -14,13 +14,18 @@ echo "*** Testing array_fill() : error conditions ***\n"; $start_key = 0; $num = -1; $val = 1; -var_dump( array_fill($start_key,$num,$val) ); -echo "Done"; +try { + var_dump( array_fill($start_key,$num,$val) ); +} catch (Error $e) { + echo $e->getMessage() . "\n"; +} + ?> + +DONE --EXPECTF-- *** Testing array_fill() : error conditions *** +Number of elements can't be negative -Warning: array_fill(): Number of elements can't be negative in %s on line %d -bool(false) -Done +DONE diff --git a/ext/standard/tests/array/array_flip.phpt b/ext/standard/tests/array/array_flip.phpt index ab8cf271b103d..06628285970b7 100644 --- a/ext/standard/tests/array/array_flip.phpt +++ b/ext/standard/tests/array/array_flip.phpt @@ -12,26 +12,39 @@ $trans = array("a" => 1, 0 => "G", 1 => "h", 2 => "i"); -$trans = array_flip($trans); + +try { + $trans = array_flip($trans); +} catch (\TypeError $e) { + echo $e->getMessage() . "\n"; +} var_dump($trans); ?> ---EXPECTF-- -Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d -Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d - -Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d -array(6) { - [1]=> - string(1) "b" - [2]=> - string(1) "c" - [0]=> - string(1) "z" - ["G"]=> - int(0) - ["h"]=> +DONE +--EXPECT-- +Can only flip STRING and INTEGER values! +array(10) { + ["a"]=> int(1) - ["i"]=> + ["b"]=> + int(1) + ["c"]=> int(2) + ["z"]=> + int(0) + ["d"]=> + bool(true) + ["E"]=> + bool(false) + ["F"]=> + NULL + [0]=> + string(1) "G" + [1]=> + string(1) "h" + [2]=> + string(1) "i" } + +DONE diff --git a/ext/standard/tests/array/array_flip_variation4.phpt b/ext/standard/tests/array/array_flip_variation4.phpt index b8badb0caade3..d49862af697e9 100644 --- a/ext/standard/tests/array/array_flip_variation4.phpt +++ b/ext/standard/tests/array/array_flip_variation4.phpt @@ -52,39 +52,20 @@ $input = array( 'resource_value' => $fp, ); -var_dump( array_flip($input) ); +try { + var_dump( array_flip($input) ); +} catch (\TypeError $e) { + echo $e->getMessage() . "\n"; +} // closing resource fclose($fp); -echo "Done" ?> ---EXPECTF-- -*** Testing array_flip() : different invalid values in 'input' array argument *** - -Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d - -Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d - -Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d - -Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d - -Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d -Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d - -Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d - -Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d - -Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d - -Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d - -Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d +DONE +--EXPECT-- +*** Testing array_flip() : different invalid values in 'input' array argument *** +Can only flip STRING and INTEGER values! -Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d -array(0) { -} -Done +DONE diff --git a/ext/standard/tests/array/array_multisort_error.phpt b/ext/standard/tests/array/array_multisort_error.phpt index 105662be07096..5d3bab456a729 100644 --- a/ext/standard/tests/array/array_multisort_error.phpt +++ b/ext/standard/tests/array/array_multisort_error.phpt @@ -12,24 +12,28 @@ echo "*** Testing array_multisort() : error conditions ***\n"; echo "\n-- Testing array_multisort() function with repeated flags --\n"; $ar1 = array(1); -var_dump( array_multisort($ar1, SORT_ASC, SORT_ASC) ); +try { + var_dump( array_multisort($ar1, SORT_ASC, SORT_ASC) ); +} catch (Error $e) { + echo $e->getMessage() . "\n"; +} echo "\n-- Testing array_multisort() function with repeated flags --\n"; $ar1 = array(1); -var_dump( array_multisort($ar1, SORT_STRING, SORT_NUMERIC) ); +try { + var_dump( array_multisort($ar1, SORT_STRING, SORT_NUMERIC) ); +} catch (Error $e) { + echo $e->getMessage() . "\n"; +} ?> ===DONE=== ---EXPECTF-- +--EXPECT-- *** Testing array_multisort() : error conditions *** -- Testing array_multisort() function with repeated flags -- - -Warning: array_multisort(): Argument #3 is expected to be an array or sorting flag that has not already been specified in %sarray_multisort_error.php on line %d -bool(false) +Argument #3 is expected to be an array or sorting flag that has not already been specified -- Testing array_multisort() function with repeated flags -- - -Warning: array_multisort(): Argument #3 is expected to be an array or sorting flag that has not already been specified in %sarray_multisort_error.php on line %d -bool(false) +Argument #3 is expected to be an array or sorting flag that has not already been specified ===DONE=== diff --git a/ext/standard/tests/array/array_multisort_variation1.phpt b/ext/standard/tests/array/array_multisort_variation1.phpt index 677a87103fc94..763944054ab70 100644 --- a/ext/standard/tests/array/array_multisort_variation1.phpt +++ b/ext/standard/tests/array/array_multisort_variation1.phpt @@ -97,111 +97,90 @@ $inputs = array( foreach($inputs as $key =>$value) { echo "\n--$key--\n"; - var_dump( array_multisort($value)); + try { + var_dump( array_multisort($value)); + } catch (Error $e) { + echo $e->getMessage() . "\n"; + } }; ?> ===DONE=== ---EXPECTF-- +--EXPECT-- *** Testing array_multisort() : usage variation *** --int 0-- -Error: 2 - array_multisort(): Argument #1 is expected to be an array or sorting flag that has not already been specified, %sarray_multisort_variation1.php(%d) -bool(false) +Argument #1 is expected to be an array or sorting flag that has not already been specified --int 1-- -Error: 2 - array_multisort(): Argument #1 is expected to be an array or sorting flag that has not already been specified, %sarray_multisort_variation1.php(%d) -bool(false) +Argument #1 is expected to be an array or sorting flag that has not already been specified --int 12345-- -Error: 2 - array_multisort(): Argument #1 is an unknown sort flag, %sarray_multisort_variation1.php(%d) -bool(false) +Argument #1 is an unknown sort flag --int -12345-- -Error: 2 - array_multisort(): Argument #1 is an unknown sort flag, %sarray_multisort_variation1.php(%d) -bool(false) +Argument #1 is an unknown sort flag --float 10.5-- -Error: 2 - array_multisort(): Argument #1 is expected to be an array or a sort flag, %sarray_multisort_variation1.php(%d) -bool(false) +Argument #1 is expected to be an array or a sort flag --float -10.5-- -Error: 2 - array_multisort(): Argument #1 is expected to be an array or a sort flag, %sarray_multisort_variation1.php(%d) -bool(false) +Argument #1 is expected to be an array or a sort flag --float 12.3456789000e10-- -Error: 2 - array_multisort(): Argument #1 is expected to be an array or a sort flag, %sarray_multisort_variation1.php(%d) -bool(false) +Argument #1 is expected to be an array or a sort flag --float -12.3456789000e10-- -Error: 2 - array_multisort(): Argument #1 is expected to be an array or a sort flag, %sarray_multisort_variation1.php(%d) -bool(false) +Argument #1 is expected to be an array or a sort flag --float .5-- -Error: 2 - array_multisort(): Argument #1 is expected to be an array or a sort flag, %sarray_multisort_variation1.php(%d) -bool(false) +Argument #1 is expected to be an array or a sort flag --uppercase NULL-- -Error: 2 - array_multisort(): Argument #1 is expected to be an array or a sort flag, %sarray_multisort_variation1.php(%d) -bool(false) +Argument #1 is expected to be an array or a sort flag --lowercase null-- -Error: 2 - array_multisort(): Argument #1 is expected to be an array or a sort flag, %sarray_multisort_variation1.php(%d) -bool(false) +Argument #1 is expected to be an array or a sort flag --lowercase true-- -Error: 2 - array_multisort(): Argument #1 is expected to be an array or a sort flag, %sarray_multisort_variation1.php(%d) -bool(false) +Argument #1 is expected to be an array or a sort flag --lowercase false-- -Error: 2 - array_multisort(): Argument #1 is expected to be an array or a sort flag, %sarray_multisort_variation1.php(%d) -bool(false) +Argument #1 is expected to be an array or a sort flag --uppercase TRUE-- -Error: 2 - array_multisort(): Argument #1 is expected to be an array or a sort flag, %sarray_multisort_variation1.php(%d) -bool(false) +Argument #1 is expected to be an array or a sort flag --uppercase FALSE-- -Error: 2 - array_multisort(): Argument #1 is expected to be an array or a sort flag, %sarray_multisort_variation1.php(%d) -bool(false) +Argument #1 is expected to be an array or a sort flag --empty string DQ-- -Error: 2 - array_multisort(): Argument #1 is expected to be an array or a sort flag, %sarray_multisort_variation1.php(%d) -bool(false) +Argument #1 is expected to be an array or a sort flag --empty string SQ-- -Error: 2 - array_multisort(): Argument #1 is expected to be an array or a sort flag, %sarray_multisort_variation1.php(%d) -bool(false) +Argument #1 is expected to be an array or a sort flag --string DQ-- -Error: 2 - array_multisort(): Argument #1 is expected to be an array or a sort flag, %sarray_multisort_variation1.php(%d) -bool(false) +Argument #1 is expected to be an array or a sort flag --string SQ-- -Error: 2 - array_multisort(): Argument #1 is expected to be an array or a sort flag, %sarray_multisort_variation1.php(%d) -bool(false) +Argument #1 is expected to be an array or a sort flag --mixed case string-- -Error: 2 - array_multisort(): Argument #1 is expected to be an array or a sort flag, %sarray_multisort_variation1.php(%d) -bool(false) +Argument #1 is expected to be an array or a sort flag --heredoc-- -Error: 2 - array_multisort(): Argument #1 is expected to be an array or a sort flag, %sarray_multisort_variation1.php(%d) -bool(false) +Argument #1 is expected to be an array or a sort flag --instance of classWithToString-- -Error: 2 - array_multisort(): Argument #1 is expected to be an array or a sort flag, %sarray_multisort_variation1.php(%d) -bool(false) +Argument #1 is expected to be an array or a sort flag --instance of classWithoutToString-- -Error: 2 - array_multisort(): Argument #1 is expected to be an array or a sort flag, %sarray_multisort_variation1.php(%d) -bool(false) +Argument #1 is expected to be an array or a sort flag --undefined var-- -Error: 2 - array_multisort(): Argument #1 is expected to be an array or a sort flag, %sarray_multisort_variation1.php(%d) -bool(false) +Argument #1 is expected to be an array or a sort flag --unset var-- -Error: 2 - array_multisort(): Argument #1 is expected to be an array or a sort flag, %sarray_multisort_variation1.php(%d) -bool(false) +Argument #1 is expected to be an array or a sort flag ===DONE=== diff --git a/ext/standard/tests/array/array_multisort_variation2.phpt b/ext/standard/tests/array/array_multisort_variation2.phpt index f9a00e9701dc5..b23d8b19fafc7 100644 --- a/ext/standard/tests/array/array_multisort_variation2.phpt +++ b/ext/standard/tests/array/array_multisort_variation2.phpt @@ -104,13 +104,17 @@ $inputs = array( // loop through each element of the array for SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]] foreach($inputs as $key =>$value) { - echo "\n--$key--\n"; - var_dump( array_multisort($ar1, $value) ); + echo "\n--$key--\n"; + try { + var_dump( array_multisort($ar1, $value) ); + } catch (Error $e) { + echo $e->getMessage() . "\n"; + } }; ?> ===DONE=== ---EXPECTF-- +--EXPECT-- *** Testing array_multisort() : usage variation *** --int 0-- @@ -120,109 +124,83 @@ bool(true) bool(true) --int 12345-- -Error: 2 - array_multisort(): Argument #2 is an unknown sort flag, %sarray_multisort_variation2.php(%d) -bool(false) +Argument #2 is an unknown sort flag --int -12345-- -Error: 2 - array_multisort(): Argument #2 is an unknown sort flag, %sarray_multisort_variation2.php(%d) -bool(false) +Argument #2 is an unknown sort flag --float 10.5-- -Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d) -bool(false) +Argument #2 is expected to be an array or a sort flag --float -10.5-- -Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d) -bool(false) +Argument #2 is expected to be an array or a sort flag --float 12.3456789000e10-- -Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d) -bool(false) +Argument #2 is expected to be an array or a sort flag --float -12.3456789000e10-- -Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d) -bool(false) +Argument #2 is expected to be an array or a sort flag --float .5-- -Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d) -bool(false) +Argument #2 is expected to be an array or a sort flag --empty array-- -Error: 2 - array_multisort(): Array sizes are inconsistent, %sarray_multisort_variation2.php(%d) -bool(false) +Array sizes are inconsistent --int indexed array-- -Error: 2 - array_multisort(): Array sizes are inconsistent, %sarray_multisort_variation2.php(%d) -bool(false) +Array sizes are inconsistent --associative array-- bool(true) --nested arrays-- -Error: 2 - array_multisort(): Array sizes are inconsistent, %sarray_multisort_variation2.php(%d) -bool(false) +Array sizes are inconsistent --uppercase NULL-- -Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d) -bool(false) +Argument #2 is expected to be an array or a sort flag --lowercase null-- -Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d) -bool(false) +Argument #2 is expected to be an array or a sort flag --lowercase true-- -Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d) -bool(false) +Argument #2 is expected to be an array or a sort flag --lowercase false-- -Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d) -bool(false) +Argument #2 is expected to be an array or a sort flag --uppercase TRUE-- -Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d) -bool(false) +Argument #2 is expected to be an array or a sort flag --uppercase FALSE-- -Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d) -bool(false) +Argument #2 is expected to be an array or a sort flag --empty string DQ-- -Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d) -bool(false) +Argument #2 is expected to be an array or a sort flag --empty string SQ-- -Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d) -bool(false) +Argument #2 is expected to be an array or a sort flag --string DQ-- -Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d) -bool(false) +Argument #2 is expected to be an array or a sort flag --string SQ-- -Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d) -bool(false) +Argument #2 is expected to be an array or a sort flag --mixed case string-- -Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d) -bool(false) +Argument #2 is expected to be an array or a sort flag --heredoc-- -Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d) -bool(false) +Argument #2 is expected to be an array or a sort flag --instance of classWithToString-- -Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d) -bool(false) +Argument #2 is expected to be an array or a sort flag --instance of classWithoutToString-- -Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d) -bool(false) +Argument #2 is expected to be an array or a sort flag --undefined var-- -Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d) -bool(false) +Argument #2 is expected to be an array or a sort flag --unset var-- -Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d) -bool(false) +Argument #2 is expected to be an array or a sort flag ===DONE=== diff --git a/ext/standard/tests/array/array_multisort_variation3.phpt b/ext/standard/tests/array/array_multisort_variation3.phpt index c625d2a56606e..42b1d9fbe571d 100644 --- a/ext/standard/tests/array/array_multisort_variation3.phpt +++ b/ext/standard/tests/array/array_multisort_variation3.phpt @@ -95,114 +95,92 @@ $inputs = array( ); // loop through each element of the array for ar2 - foreach($inputs as $key =>$value) { - echo "\n--$key--\n"; - var_dump( array_multisort($ar1, SORT_REGULAR, $value) ); + echo "\n--$key--\n"; + try { + var_dump( array_multisort($ar1, SORT_REGULAR, $value) ); + } catch (Error $e) { + echo $e->getMessage() . "\n"; + } }; ?> ===DONE=== ---EXPECTF-- +--EXPECT-- *** Testing array_multisort() : usage variation *** --int 0-- -Error: 2 - array_multisort(): Argument #3 is expected to be an array or sorting flag that has not already been specified, %sarray_multisort_variation3.php(%d) -bool(false) +Argument #3 is expected to be an array or sorting flag that has not already been specified --int 1-- -Error: 2 - array_multisort(): Argument #3 is expected to be an array or sorting flag that has not already been specified, %sarray_multisort_variation3.php(%d) -bool(false) +Argument #3 is expected to be an array or sorting flag that has not already been specified --int 12345-- -Error: 2 - array_multisort(): Argument #3 is an unknown sort flag, %sarray_multisort_variation3.php(%d) -bool(false) +Argument #3 is an unknown sort flag --int -12345-- -Error: 2 - array_multisort(): Argument #3 is an unknown sort flag, %sarray_multisort_variation3.php(%d) -bool(false) +Argument #3 is an unknown sort flag --float 10.5-- -Error: 2 - array_multisort(): Argument #3 is expected to be an array or a sort flag, %sarray_multisort_variation3.php(%d) -bool(false) +Argument #3 is expected to be an array or a sort flag --float -10.5-- -Error: 2 - array_multisort(): Argument #3 is expected to be an array or a sort flag, %sarray_multisort_variation3.php(%d) -bool(false) +Argument #3 is expected to be an array or a sort flag --float 12.3456789000e10-- -Error: 2 - array_multisort(): Argument #3 is expected to be an array or a sort flag, %sarray_multisort_variation3.php(%d) -bool(false) +Argument #3 is expected to be an array or a sort flag --float -12.3456789000e10-- -Error: 2 - array_multisort(): Argument #3 is expected to be an array or a sort flag, %sarray_multisort_variation3.php(%d) -bool(false) +Argument #3 is expected to be an array or a sort flag --float .5-- -Error: 2 - array_multisort(): Argument #3 is expected to be an array or a sort flag, %sarray_multisort_variation3.php(%d) -bool(false) +Argument #3 is expected to be an array or a sort flag --uppercase NULL-- -Error: 2 - array_multisort(): Argument #3 is expected to be an array or a sort flag, %sarray_multisort_variation3.php(%d) -bool(false) +Argument #3 is expected to be an array or a sort flag --lowercase null-- -Error: 2 - array_multisort(): Argument #3 is expected to be an array or a sort flag, %sarray_multisort_variation3.php(%d) -bool(false) +Argument #3 is expected to be an array or a sort flag --lowercase true-- -Error: 2 - array_multisort(): Argument #3 is expected to be an array or a sort flag, %sarray_multisort_variation3.php(%d) -bool(false) +Argument #3 is expected to be an array or a sort flag --lowercase false-- -Error: 2 - array_multisort(): Argument #3 is expected to be an array or a sort flag, %sarray_multisort_variation3.php(%d) -bool(false) +Argument #3 is expected to be an array or a sort flag --uppercase TRUE-- -Error: 2 - array_multisort(): Argument #3 is expected to be an array or a sort flag, %sarray_multisort_variation3.php(%d) -bool(false) +Argument #3 is expected to be an array or a sort flag --uppercase FALSE-- -Error: 2 - array_multisort(): Argument #3 is expected to be an array or a sort flag, %sarray_multisort_variation3.php(%d) -bool(false) +Argument #3 is expected to be an array or a sort flag --empty string DQ-- -Error: 2 - array_multisort(): Argument #3 is expected to be an array or a sort flag, %sarray_multisort_variation3.php(%d) -bool(false) +Argument #3 is expected to be an array or a sort flag --empty string SQ-- -Error: 2 - array_multisort(): Argument #3 is expected to be an array or a sort flag, %sarray_multisort_variation3.php(%d) -bool(false) +Argument #3 is expected to be an array or a sort flag --string DQ-- -Error: 2 - array_multisort(): Argument #3 is expected to be an array or a sort flag, %sarray_multisort_variation3.php(%d) -bool(false) +Argument #3 is expected to be an array or a sort flag --string SQ-- -Error: 2 - array_multisort(): Argument #3 is expected to be an array or a sort flag, %sarray_multisort_variation3.php(%d) -bool(false) +Argument #3 is expected to be an array or a sort flag --mixed case string-- -Error: 2 - array_multisort(): Argument #3 is expected to be an array or a sort flag, %sarray_multisort_variation3.php(%d) -bool(false) +Argument #3 is expected to be an array or a sort flag --heredoc-- -Error: 2 - array_multisort(): Argument #3 is expected to be an array or a sort flag, %sarray_multisort_variation3.php(%d) -bool(false) +Argument #3 is expected to be an array or a sort flag --instance of classWithToString-- -Error: 2 - array_multisort(): Argument #3 is expected to be an array or a sort flag, %sarray_multisort_variation3.php(%d) -bool(false) +Argument #3 is expected to be an array or a sort flag --instance of classWithoutToString-- -Error: 2 - array_multisort(): Argument #3 is expected to be an array or a sort flag, %sarray_multisort_variation3.php(%d) -bool(false) +Argument #3 is expected to be an array or a sort flag --undefined var-- -Error: 2 - array_multisort(): Argument #3 is expected to be an array or a sort flag, %sarray_multisort_variation3.php(%d) -bool(false) +Argument #3 is expected to be an array or a sort flag --unset var-- -Error: 2 - array_multisort(): Argument #3 is expected to be an array or a sort flag, %sarray_multisort_variation3.php(%d) -bool(false) +Argument #3 is expected to be an array or a sort flag ===DONE=== diff --git a/ext/standard/tests/array/array_pad.phpt b/ext/standard/tests/array/array_pad.phpt index fd5fa520b62c8..fdde153e20a64 100644 --- a/ext/standard/tests/array/array_pad.phpt +++ b/ext/standard/tests/array/array_pad.phpt @@ -12,11 +12,17 @@ var_dump(array_pad(array("", -1, 2.0), 5, array())); var_dump(array_pad(array("", -1, 2.0), 2, array())); var_dump(array_pad(array("", -1, 2.0), -3, array())); var_dump(array_pad(array("", -1, 2.0), -4, array())); -var_dump(array_pad(array("", -1, 2.0), 2000000, 0)); -echo "Done\n"; +try { + var_dump(array_pad(array("", -1, 2.0), 2000000, 0)); +} catch (Error $e) { + echo $e->getMessage() . "\n"; +} + ?> ---EXPECTF-- + +DONE +--EXPECT-- array(1) { [0]=> int(0) @@ -80,7 +86,6 @@ array(4) { [3]=> float(2) } +Only 1048576 elements may be pad up at a time. -Warning: array_pad(): You may only pad up to 1048576 elements at a time in %s on line %d -bool(false) -Done +DONE diff --git a/ext/standard/tests/array/array_push_error2.phpt b/ext/standard/tests/array/array_push_error2.phpt index 3ab60136bea82..2d19dbc2465fa 100644 --- a/ext/standard/tests/array/array_push_error2.phpt +++ b/ext/standard/tests/array/array_push_error2.phpt @@ -15,17 +15,18 @@ Test array_push() function : error conditions - max int value as key echo "*** Testing array_push() : error conditions ***\n"; $array = array(PHP_INT_MAX => 'max'); - -var_dump(array_push($array, 'new')); +try { + var_dump(array_push($array, 'new')); +} catch (\Error $e) { + echo $e->getMessage() . "\n"; +} var_dump($array); echo "Done"; ?> --EXPECTF-- *** Testing array_push() : error conditions *** - -Warning: array_push(): Cannot add element to the array as the next element is already occupied in %s on line %d -bool(false) +Cannot add element to the array as the next element is already occupied array(1) { [%d]=> string(3) "max" diff --git a/ext/standard/tests/array/array_rand.phpt b/ext/standard/tests/array/array_rand.phpt index 72999eda5fdd6..589572754829b 100644 --- a/ext/standard/tests/array/array_rand.phpt +++ b/ext/standard/tests/array/array_rand.phpt @@ -3,31 +3,47 @@ array_rand() tests --FILE-- getMessage() . "\n"; +} + +try { + var_dump(array_rand(array(), 0)); +} catch (\Error $e) { + echo $e->getMessage() . "\n"; +} + +try { + var_dump(array_rand(array(1,2,3), 0)); +} catch (\Error $e) { + echo $e->getMessage() . "\n"; +} + +try { + var_dump(array_rand(array(1,2,3), -1)); +} catch (\Error $e) { + echo $e->getMessage() . "\n"; +} + +try { + var_dump(array_rand(array(1,2,3), 10)); +} catch (\Error $e) { + echo $e->getMessage() . "\n"; +} + var_dump(array_rand(array(1,2,3), 3)); var_dump(array_rand(array(1,2,3), 2)); echo "Done\n"; ?> --EXPECTF-- -Warning: array_rand(): Array is empty in %s on line %d -NULL - -Warning: array_rand(): Array is empty in %s on line %d -NULL - -Warning: array_rand(): Second argument has to be between 1 and the number of elements in the array in %s on line %d -NULL - -Warning: array_rand(): Second argument has to be between 1 and the number of elements in the array in %s on line %d -NULL - -Warning: array_rand(): Second argument has to be between 1 and the number of elements in the array in %s on line %d -NULL +Array is empty +Array is empty +Second argument has to be between 1 and the number of elements in the array +Second argument has to be between 1 and the number of elements in the array +Second argument has to be between 1 and the number of elements in the array array(3) { [0]=> int(%d) diff --git a/ext/standard/tests/array/array_rand_variation5.phpt b/ext/standard/tests/array/array_rand_variation5.phpt index 30eb7d780104f..03e20d6e07a87 100644 --- a/ext/standard/tests/array/array_rand_variation5.phpt +++ b/ext/standard/tests/array/array_rand_variation5.phpt @@ -32,17 +32,36 @@ var_dump( array_rand($input, 1) ); // with valid $num_req value // with invalid num_req value echo"\n-- With num_req = 0 --\n"; -var_dump( array_rand($input, 0) ); // with $num_req=0 +try { + var_dump( array_rand($input, 0) ); // with $num_req=0 +} catch (\Error $e) { + echo $e->getMessage() . "\n"; +} + echo"\n-- With num_req = -1 --\n"; -var_dump( array_rand($input, -1) ); // with $num_req=-1 +try { + var_dump( array_rand($input, -1) ); // with $num_req=-1 +} catch (\Error $e) { + echo $e->getMessage() . "\n"; +} + echo"\n-- With num_req = -2 --\n"; -var_dump( array_rand($input, -2) ); // with $num_req=-2 -echo"\n-- With num_req more than number of members in 'input' array --\n"; -var_dump( array_rand($input, 13) ); // with $num_req=13 +try { + var_dump( array_rand($input, -2) ); // with $num_req=-2 +} catch (\Error $e) { + echo $e->getMessage() . "\n"; +} +echo"\n-- With num_req more than number of members in 'input' array --\n"; +try { + var_dump( array_rand($input, 13) ); // with $num_req=13 +} catch (\Error $e) { + echo $e->getMessage() . "\n"; +} -echo "Done"; ?> + +DONE --EXPECTF-- *** Testing array_rand() : with invalid values for 'req_num' *** @@ -53,22 +72,15 @@ int(%d) int(%d) -- With num_req = 0 -- - -Warning: array_rand(): Second argument has to be between 1 and the number of elements in the array in %s on line %d -NULL +Second argument has to be between 1 and the number of elements in the array -- With num_req = -1 -- - -Warning: array_rand(): Second argument has to be between 1 and the number of elements in the array in %s on line %d -NULL +Second argument has to be between 1 and the number of elements in the array -- With num_req = -2 -- - -Warning: array_rand(): Second argument has to be between 1 and the number of elements in the array in %s on line %d -NULL +Second argument has to be between 1 and the number of elements in the array -- With num_req more than number of members in 'input' array -- +Second argument has to be between 1 and the number of elements in the array -Warning: array_rand(): Second argument has to be between 1 and the number of elements in the array in %s on line %d -NULL -Done +DONE diff --git a/ext/standard/tests/array/array_replace.phpt b/ext/standard/tests/array/array_replace.phpt index 6ba9e43fd753d..48b616ab04ee6 100644 --- a/ext/standard/tests/array/array_replace.phpt +++ b/ext/standard/tests/array/array_replace.phpt @@ -42,11 +42,15 @@ $data = array_replace_recursive($array1, $array2); var_dump($data); echo " -- Testing array_replace_recursive() w/ endless recusrsion --\n"; -$data = array_replace_recursive($array3, $array4); +try { + $data = array_replace_recursive($array3, $array4); + var_dump($data); +} catch (\Error $e) { + echo $e->getMessage() . "\n"; +} -var_dump($data); ?> ---EXPECTF-- +--EXPECT-- -- Testing array_replace() -- array(5) { [0]=> @@ -107,16 +111,4 @@ array(5) { } } -- Testing array_replace_recursive() w/ endless recusrsion -- - -Warning: array_replace_recursive(): recursion detected in %s on line %d -array(1) { - [0]=> - array(1) { - [0]=> - array(1) { - [0]=> - array(0) { - } - } - } -} +Recursion detected diff --git a/ext/standard/tests/array/bug42177.phpt b/ext/standard/tests/array/bug42177.phpt index 5678ca3cac896..dc5297b302042 100644 --- a/ext/standard/tests/array/bug42177.phpt +++ b/ext/standard/tests/array/bug42177.phpt @@ -18,7 +18,11 @@ unset( $a1, $a2 ); $a1 = array(); $a2 = array( 'key1' => &$a1 ); $a1 = array_merge_recursive( $a1, $a2 ); -$a1 = array_merge_recursive( $a1, $a2 ); +try { + $a1 = array_merge_recursive( $a1, $a2 ); +} catch (\Error $e) { + echo $e->getMessage() . " on line " . $e->getLine() . "\n"; +} unset( $a1, $a2 ); $x = 'foo'; @@ -30,5 +34,5 @@ $a1 = array_merge_recursive( $a1, $a2 ); unset( $a1, $a2 ); ?> ---EXPECTF-- -Warning: array_merge_recursive(): recursion detected in %s on line 18 +--EXPECT-- +Recursion detected on line 19 diff --git a/ext/standard/tests/array/bug43495.phpt b/ext/standard/tests/array/bug43495.phpt index 522ff1903b5d4..cb011d3d44f29 100644 --- a/ext/standard/tests/array/bug43495.phpt +++ b/ext/standard/tests/array/bug43495.phpt @@ -8,14 +8,21 @@ $a["key1"]["key2"]["key3"]=&$a; $b=array("key1"=>array("key2"=>array())); $b["key1"]["key2"]["key3"]=&$b; -array_merge_recursive($a,$b); + +try { + array_merge_recursive($a,$b); +} catch (\Error $e) { + echo $e->getMessage() . "\n"; +} /* Break recursion */ $a["key1"]["key2"]["key3"] = null; $b["key1"]["key2"]["key3"] = null; -echo "Done.\n"; ?> ---EXPECTF-- -Warning: array_merge_recursive(): recursion detected in %sbug43495.php on line %d -Done. + +DONE +--EXPECT-- +Recursion detected + +DONE diff --git a/ext/standard/tests/array/bug61058.phpt b/ext/standard/tests/array/bug61058.phpt index f5e06a4a02d16..6e78b357117eb 100644 --- a/ext/standard/tests/array/bug61058.phpt +++ b/ext/standard/tests/array/bug61058.phpt @@ -2,7 +2,12 @@ Bug #61058 (array_fill leaks if start index is PHP_INT_MAX) --FILE-- getMessage() . "\n"; +} ?> ---EXPECTF-- -Warning: array_fill(): Cannot add element to the array as the next element is already occupied in %sbug61058.php on line %d +--EXPECT-- +Cannot add element to the array as the next element is already occupied diff --git a/ext/standard/tests/array/bug65251.phpt b/ext/standard/tests/array/bug65251.phpt index 014517794c703..3e0f3a1e27c86 100644 --- a/ext/standard/tests/array/bug65251.phpt +++ b/ext/standard/tests/array/bug65251.phpt @@ -3,8 +3,12 @@ Bug #65251: array_merge_recursive() recursion detection broken --FILE-- getMessage() . "\n"; +} ?> ---EXPECTF-- -Warning: array_merge_recursive(): recursion detected in %s on line %d +--EXPECT-- +Recursion detected diff --git a/ext/standard/tests/array/bug70713.phpt b/ext/standard/tests/array/bug70713.phpt index 7cd0a0f113f59..f24720607d1b6 100644 --- a/ext/standard/tests/array/bug70713.phpt +++ b/ext/standard/tests/array/bug70713.phpt @@ -19,8 +19,13 @@ class obj } $arr = array('string' => new obj); -array_walk_recursive($arr, 'settype'); + +try { + array_walk_recursive($arr, 'settype'); +} catch (\TypeError $e) { + echo $e->getMessage() . "\n"; +} ?> ---EXPECTF-- -Warning: array_walk_recursive(): Iterated value is no longer an array or object in %s on line %d +--EXPECT-- +Iterated value is no longer an array or object diff --git a/ext/standard/tests/array/bug77395.phpt b/ext/standard/tests/array/bug77395.phpt index 7910e36982dcc..b90e9dd9765dd 100644 --- a/ext/standard/tests/array/bug77395.phpt +++ b/ext/standard/tests/array/bug77395.phpt @@ -10,7 +10,12 @@ function error_handle($level, $message, $file = '', $line = 0){ } set_error_handler('error_handle'); $data = [['aa'=> 'bb',], ['aa'=> 'bb',],]; -array_multisort(array_column($data, 'bb'),SORT_DESC, $data); // PHP Warning error + +try { + array_multisort(array_column($data, 'bb'),SORT_DESC, $data); // PHP Warning error +} catch (\Error $e) { + echo $e->getMessage() . "\n"; +} ?> --EXPECT-- -array_multisort(): Array sizes are inconsistent +Array sizes are inconsistent diff --git a/ext/standard/tests/array/compact_variation1.phpt b/ext/standard/tests/array/compact_variation1.phpt index d2b9fc45df0c7..9201bc5aa1159 100644 --- a/ext/standard/tests/array/compact_variation1.phpt +++ b/ext/standard/tests/array/compact_variation1.phpt @@ -10,7 +10,7 @@ Test compact() function : usage variations - arrays containing references. /* * compact variations - arrays with references */ -echo "*** Testing compact() : usage variations - arrays containg references ***\n"; +echo "*** Testing compact() : usage variations - arrays containing references ***\n"; $a = 1; $b = 2; $c = 3; @@ -20,31 +20,34 @@ $arr2 = array("a", array(array(array("b")))); $arr2[1][0][0][] = &$arr2; $arr2[1][0][0][] = &$arr2[1]; $arr3 = array(&$string); -var_dump(compact($arr1)); -var_dump(compact($arr2)); -var_dump(compact($arr3)); -echo "Done"; -?> ---EXPECTF-- -*** Testing compact() : usage variations - arrays containg references *** -Warning: compact(): recursion detected in %s on line %d -array(1) { - ["a"]=> - int(1) +try { + var_dump(compact($arr1)); +} catch (\Error $e) { + echo $e->getMessage() . "\n"; } -Warning: compact(): recursion detected in %s on line %d +try { + var_dump(compact($arr2)); +} catch (\Error $e) { + echo $e->getMessage() . "\n"; +} -Warning: compact(): recursion detected in %s on line %d -array(2) { - ["a"]=> - int(1) - ["b"]=> - int(2) +try { + var_dump(compact($arr3)); +} catch (\Error $e) { + echo $e->getMessage() . "\n"; } +?> + +DONE +--EXPECT-- +*** Testing compact() : usage variations - arrays containing references *** +Recursion detected +Recursion detected array(1) { ["c"]=> int(3) } -Done + +DONE diff --git a/ext/standard/tests/array/count_errors.phpt b/ext/standard/tests/array/count_errors.phpt new file mode 100644 index 0000000000000..aacad5210d34b --- /dev/null +++ b/ext/standard/tests/array/count_errors.phpt @@ -0,0 +1,74 @@ +--TEST-- +Test count() function error conditions +--FILE-- +getMessage() . "\n"; +} +try { + count(NULL, COUNT_RECURSIVE); +} catch (\TypeError $e) { + echo $e->getMessage() . "\n"; +} +try { + count(NULL); +} catch (\TypeError $e) { + echo $e->getMessage() . "\n"; +} + +try { + count("string", COUNT_NORMAL); +} catch (\TypeError $e) { + echo $e->getMessage() . "\n"; +} +try { + count("string", COUNT_RECURSIVE); +} catch (\TypeError $e) { + echo $e->getMessage() . "\n"; +} +try { + count("string"); +} catch (\TypeError $e) { + echo $e->getMessage() . "\n"; +} +try { + count(""); +} catch (\TypeError $e) { + echo $e->getMessage() . "\n"; +} + +try { + count(100); +} catch (\TypeError $e) { + echo $e->getMessage() . "\n"; +} +try { + count(-23.45); +} catch (\TypeError $e) { + echo $e->getMessage() . "\n"; +} + +try { + @count($a); +} catch (\TypeError $e) { + echo $e->getMessage() . "\n"; +} + +?> +--EXPECT-- +Parameter must be an array or an object that implements Countable +Parameter must be an array or an object that implements Countable +Parameter must be an array or an object that implements Countable +Parameter must be an array or an object that implements Countable +Parameter must be an array or an object that implements Countable +Parameter must be an array or an object that implements Countable +Parameter must be an array or an object that implements Countable +Parameter must be an array or an object that implements Countable +Parameter must be an array or an object that implements Countable +Parameter must be an array or an object that implements Countable diff --git a/ext/standard/tests/array/count_invalid.phpt b/ext/standard/tests/array/count_invalid.phpt index 95da00dac5100..5ce25028e2e1f 100644 --- a/ext/standard/tests/array/count_invalid.phpt +++ b/ext/standard/tests/array/count_invalid.phpt @@ -3,40 +3,51 @@ Only arrays and countable objects can be counted --FILE-- getMessage() . "\n"; +} + +try { + $result = count("string"); + var_dump($result); +} catch (\TypeError $e) { + echo $e->getMessage() . "\n"; +} + +try { + $result = count(123); + var_dump($result); +} catch (\TypeError $e) { + echo $e->getMessage() . "\n"; +} + +try { + $result = count(true); + var_dump($result); +} catch (\TypeError $e) { + echo $e->getMessage() . "\n"; +} +try { + $result = count(false); + var_dump($result); +} catch (\TypeError $e) { + echo $e->getMessage() . "\n"; +} +try { + $result = count((object) []); + var_dump($result); +} catch (\TypeError $e) { + echo $e->getMessage() . "\n"; +} ?> ---EXPECTF-- -Warning: count(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) - -Warning: count(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) - -Warning: count(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) - -Warning: count(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) - -Warning: count(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) - -Warning: count(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +--EXPECT-- +Parameter must be an array or an object that implements Countable +Parameter must be an array or an object that implements Countable +Parameter must be an array or an object that implements Countable +Parameter must be an array or an object that implements Countable +Parameter must be an array or an object that implements Countable +Parameter must be an array or an object that implements Countable diff --git a/ext/standard/tests/array/count_recursive.phpt b/ext/standard/tests/array/count_recursive.phpt index 1fd2e8e6cafce..3d0558a05423c 100644 --- a/ext/standard/tests/array/count_recursive.phpt +++ b/ext/standard/tests/array/count_recursive.phpt @@ -3,15 +3,10 @@ Test count() function --FILE-- 1, "b" => 2, array("c" => 3, array("d" => 5))); print "COUNT_NORMAL: should be 3, is ".count($arr, COUNT_NORMAL)."\n"; print "COUNT_RECURSIVE: should be 6, is ".count($arr, COUNT_RECURSIVE)."\n"; -print "-- Testing strings --\n"; -print "COUNT_NORMAL: should be 1, is ".count("string", COUNT_NORMAL)."\n"; -print "COUNT_RECURSIVE: should be 1, is ".count("string", COUNT_RECURSIVE)."\n"; - -print "-- Testing various types with no second argument --\n"; -print "COUNT_NORMAL: should be 1, is ".count("string")."\n"; +print "-- Testing array with no second argument --\n"; print "COUNT_NORMAL: should be 2, is ".count(array("a", array("b")))."\n"; $arr = array('a'=>array(NULL, NULL, NULL), 1=>array(NULL=>1, 1=>NULL), @@ -38,40 +28,24 @@ print "COUNT_RECURSIVE: should be 13, is ".count($arr, COUNT_RECURSIVE)."\n"; echo "\n*** Testing possible variations of count() function on arrays ***"; $count_array = array( - array(), - array( 1 => "string"), - array( "" => "string", 0 => "a", NULL => "b", -1.00 => "c", - array(array(array(NULL)))), - array( -2.44444 => 12, array(array(1, 2, array(array("0"))))), - array( "a" => 1, "b" => -2.344, "b" => "string", "c" => NULL, "d" => -2.344), - array( 4 => 1, 3 => -2.344, "3" => "string", "2" => NULL, - 1 => -2.344, array()), - array( TRUE => TRUE, FALSE => FALSE, "" => "", " " => " ", - NULL => NULL, "\x000" => "\x000", "\000" => "\000"), - array( NULL, 1.23 => "Hi", "string" => "hello", - array("" => "World", "-2.34" => "a", "0" => "b")) + array(), + array( 1 => "string"), + array( "" => "string", 0 => "a", NULL => "b", -1.00 => "c", array(array(array(NULL)))), + array( -2.44444 => 12, array(array(1, 2, array(array("0"))))), + array( "a" => 1, "b" => -2.344, "b" => "string", "c" => NULL, "d" => -2.344), + array( 4 => 1, 3 => -2.344, "3" => "string", "2" => NULL, 1 => -2.344, array()), + array( TRUE => TRUE, FALSE => FALSE, "" => "", " " => " ", NULL => NULL, "\x000" => "\x000", "\000" => "\000"), + array( NULL, 1.23 => "Hi", "string" => "hello", array("" => "World", "-2.34" => "a", "0" => "b") ) ); $i = 0; foreach ($count_array as $count_value) { - echo "\n-- Iteration $i --\n"; - print "COUNT_NORMAL is ".count($count_value, COUNT_NORMAL)."\n"; - print "COUNT_RECURSIVE is ".count($count_value, COUNT_RECURSIVE)."\n"; - $i++; + echo "\n-- Iteration $i --\n"; + print "COUNT_NORMAL is ".count($count_value, COUNT_NORMAL)."\n"; + print "COUNT_RECURSIVE is ".count($count_value, COUNT_RECURSIVE)."\n"; + $i++; } - -/* Testing count() by passing constant with no second argument */ -print "\n-- Testing count() on constants with no second argument --\n"; -print "COUNT_NORMAL: should be 1, is ".count(100)."\n"; -print "COUNT_NORMAL: should be 1, is ".count(-23.45)."\n"; - -print "\n-- Testing count() on NULL and Unset variables --\n"; -print "COUNT_NORMAL: should be 0, is ".count(NULL)."\n"; -print "COUNT_NORMAL: should be 1, is ".count("")."\n"; -print "COUNT_NORMAL: should be 0, is ".@count($a)."\n"; - - print "\n-- Testing count() on an empty sub-array --\n"; $arr = array(1, array(3, 4, array())); print "COUNT_NORMAL: should be 2, is ".count($arr, COUNT_NORMAL)."\n"; @@ -117,32 +91,15 @@ echo "\nDone"; fclose( $resource1 ); closedir( $resource2 ); ?> ---EXPECTF-- +--EXPECT-- *** Testing basic functionality of count() function *** --- Testing NULL -- - -Warning: count(): Parameter must be an array or an object that implements Countable in %s on line %d -COUNT_NORMAL: should be 0, is 0 - -Warning: count(): Parameter must be an array or an object that implements Countable in %s on line %d -COUNT_RECURSIVE: should be 0, is 0 -- Testing arrays -- COUNT_NORMAL: should be 2, is 2 COUNT_RECURSIVE: should be 8, is 8 -- Testing hashes -- COUNT_NORMAL: should be 3, is 3 COUNT_RECURSIVE: should be 6, is 6 --- Testing strings -- - -Warning: count(): Parameter must be an array or an object that implements Countable in %s on line %d -COUNT_NORMAL: should be 1, is 1 - -Warning: count(): Parameter must be an array or an object that implements Countable in %s on line %d -COUNT_RECURSIVE: should be 1, is 1 --- Testing various types with no second argument -- - -Warning: count(): Parameter must be an array or an object that implements Countable in %s on line %d -COUNT_NORMAL: should be 1, is 1 +-- Testing array with no second argument -- COUNT_NORMAL: should be 2, is 2 -- Testing really cool arrays -- COUNT_NORMAL: should be 3, is 3 @@ -181,23 +138,6 @@ COUNT_RECURSIVE is 6 COUNT_NORMAL is 4 COUNT_RECURSIVE is 7 --- Testing count() on constants with no second argument -- - -Warning: count(): Parameter must be an array or an object that implements Countable in %s on line %d -COUNT_NORMAL: should be 1, is 1 - -Warning: count(): Parameter must be an array or an object that implements Countable in %s on line %d -COUNT_NORMAL: should be 1, is 1 - --- Testing count() on NULL and Unset variables -- - -Warning: count(): Parameter must be an array or an object that implements Countable in %s on line %d -COUNT_NORMAL: should be 0, is 0 - -Warning: count(): Parameter must be an array or an object that implements Countable in %s on line %d -COUNT_NORMAL: should be 1, is 1 -COUNT_NORMAL: should be 0, is 0 - -- Testing count() on an empty sub-array -- COUNT_NORMAL: should be 2, is 2 COUNT_RECURSIVE: should be 5, is 5 diff --git a/ext/standard/tests/array/count_variation3.phpt b/ext/standard/tests/array/count_variation3.phpt index 30cae18964a0d..0ca0cc2bfbc8d 100644 --- a/ext/standard/tests/array/count_variation3.phpt +++ b/ext/standard/tests/array/count_variation3.phpt @@ -22,18 +22,21 @@ echo "\n-- \$mode not set: --\n"; var_dump(count ($array1)); echo "\n-- \$mode = 1: --\n"; -var_dump(count ($array1, 1)); + +try { + var_dump(count ($array1, 1)); +} catch (\Error $e) { + echo $e->getMessage(), "\n"; +} echo "Done"; ?> ---EXPECTF-- +--EXPECT-- *** Testing count() : usage variations *** -- $mode not set: -- int(4) -- $mode = 1: -- - -Warning: count(): recursion detected in %s on line %d -int(4) +Recursion detected Done diff --git a/ext/standard/tests/array/extract_error.phpt b/ext/standard/tests/array/extract_error.phpt index 08e1824b0fb30..c03212973ebe4 100644 --- a/ext/standard/tests/array/extract_error.phpt +++ b/ext/standard/tests/array/extract_error.phpt @@ -8,11 +8,25 @@ echo "*** Testing Error Conditions ***\n"; /* Invalid second argument ( only 0-6 is valid) */ $arr = array(1); -var_dump( extract($arr, -1 . "wddr") ); -var_dump( extract($arr, 7 , "wddr") ); + +try { + var_dump( extract($arr, -1 . "wddr") ); +} catch (\Error $e) { + echo $e->getMessage() . "\n"; +} + +try { + var_dump( extract($arr, 7 , "wddr") ); +} catch (\Error $e) { + echo $e->getMessage() . "\n"; +} /* Two Arguments, second as prefix but without prefix string as third argument */ -var_dump( extract($arr,EXTR_PREFIX_IF_EXISTS) ); +try { + var_dump( extract($arr,EXTR_PREFIX_IF_EXISTS) ); +} catch (\Error $e) { + echo $e->getMessage() . "\n"; +} echo "Done\n"; ?> @@ -20,13 +34,7 @@ echo "Done\n"; *** Testing Error Conditions *** Notice: A non well formed numeric value encountered in %s on line %d - -Warning: extract(): Invalid extract type in %s on line %d -NULL - -Warning: extract(): Invalid extract type in %s on line %d -NULL - -Warning: extract(): specified extract type requires the prefix parameter in %s on line %d -NULL +Invalid extract type +Invalid extract type +specified extract type requires the prefix parameter Done diff --git a/ext/standard/tests/array/max.phpt b/ext/standard/tests/array/max.phpt index df471ef255945..11769b384a8ba 100644 --- a/ext/standard/tests/array/max.phpt +++ b/ext/standard/tests/array/max.phpt @@ -5,9 +5,24 @@ precision=14 --FILE-- getMessage() . "\n"; +} + +try { + var_dump(min(array())); +} catch (\Error $e) { + echo $e->getMessage() . "\n"; +} + +try { + var_dump(min(new stdclass)); +} catch (\TypeError $e) { + echo $e->getMessage() . "\n"; +} + var_dump(max(2,1,2)); var_dump(max(2.1,2.11,2.09)); var_dump(max("", "t", "b")); @@ -18,15 +33,10 @@ var_dump(max(0, true, false, true)); echo "Done\n"; ?> ---EXPECTF-- -Warning: max(): When only one parameter is given, it must be an array in %s on line %d -NULL - -Warning: max(): Array must contain at least one element in %s on line %d -bool(false) - -Warning: max(): When only one parameter is given, it must be an array in %s on line %d -NULL +--EXPECT-- +When only one parameter is given, it must be an array +Array must contain at least one element +When only one parameter is given, it must be an array int(2) float(2.11) string(1) "t" diff --git a/ext/standard/tests/array/min.phpt b/ext/standard/tests/array/min.phpt index 031e9b2c96b00..85defa6e855fb 100644 --- a/ext/standard/tests/array/min.phpt +++ b/ext/standard/tests/array/min.phpt @@ -5,9 +5,24 @@ precision=14 --FILE-- getMessage() . "\n"; +} + +try { + var_dump(min(array())); +} catch (\Error $e) { + echo $e->getMessage() . "\n"; +} + +try { + var_dump(min(new stdclass)); +} catch (\TypeError $e) { + echo $e->getMessage() . "\n"; +} + var_dump(min(2,1,2)); var_dump(min(2.1,2.11,2.09)); var_dump(min("", "t", "b")); @@ -18,15 +33,10 @@ var_dump(min(0, true, false, true)); echo "Done\n"; ?> ---EXPECTF-- -Warning: min(): When only one parameter is given, it must be an array in %s on line %d -NULL - -Warning: min(): Array must contain at least one element in %s on line %d -bool(false) - -Warning: min(): When only one parameter is given, it must be an array in %s on line %d -NULL +--EXPECT-- +When only one parameter is given, it must be an array +Array must contain at least one element +When only one parameter is given, it must be an array int(1) float(2.09) string(0) "" diff --git a/ext/standard/tests/array/range_bug70239_0.phpt b/ext/standard/tests/array/range_bug70239_0.phpt index edfdd05fbc404..c902a168b2e0a 100644 --- a/ext/standard/tests/array/range_bug70239_0.phpt +++ b/ext/standard/tests/array/range_bug70239_0.phpt @@ -2,9 +2,13 @@ Bug #70239 Creating a huge array doesn't result in exhausted, but segfault, var 1 --FILE-- getMessage() . "\n"; +} ?> ===DONE=== ---EXPECTF-- -Warning: range(): Invalid range supplied: start=0 end=inf in %srange_bug70239_0.php on line %d +--EXPECT-- +Invalid range supplied: start=0 end=inf ===DONE=== diff --git a/ext/standard/tests/array/range_bug70239_1.phpt b/ext/standard/tests/array/range_bug70239_1.phpt index 75419cf829c76..6d12348f679bd 100644 --- a/ext/standard/tests/array/range_bug70239_1.phpt +++ b/ext/standard/tests/array/range_bug70239_1.phpt @@ -2,9 +2,13 @@ Bug #70239 Creating a huge array doesn't result in exhausted, but segfault, var 2 --FILE-- getMessage() . "\n"; +} ?> ===DONE=== ---EXPECTF-- -Warning: range(): Invalid range supplied: start=inf end=inf in %srange_bug70239_1.php on line %d +--EXPECT-- +Invalid range supplied: start=inf end=inf ===DONE=== diff --git a/ext/standard/tests/array/range_bug70239_2.phpt b/ext/standard/tests/array/range_bug70239_2.phpt index 76ed638669f4c..c9396b3cb4dc1 100644 --- a/ext/standard/tests/array/range_bug70239_2.phpt +++ b/ext/standard/tests/array/range_bug70239_2.phpt @@ -2,10 +2,13 @@ Bug #70239 Creating a huge array doesn't result in exhausted, but segfault, var 3 --FILE-- getMessage() . "\n"; +} ?> ===DONE=== --EXPECTF-- -Warning: range(): The supplied range exceeds the maximum array size: start=0 end=%d in %srange_bug70239_2.php on line %d -bool(false) +The supplied range exceeds the maximum array size: start=0 end=%d ===DONE=== diff --git a/ext/standard/tests/array/range_bug70239_3.phpt b/ext/standard/tests/array/range_bug70239_3.phpt index 8402870c82782..e49267bfe377c 100644 --- a/ext/standard/tests/array/range_bug70239_3.phpt +++ b/ext/standard/tests/array/range_bug70239_3.phpt @@ -2,10 +2,13 @@ Bug #70239 Creating a huge array doesn't result in exhausted, but segfault, var 4 --FILE-- getMessage() . "\n"; +} ?> ===DONE=== --EXPECTF-- -Warning: range(): The supplied range exceeds the maximum array size: start=-%d end=0 in %srange_bug70239_3.php on line %d -bool(false) +The supplied range exceeds the maximum array size: start=-%d end=0 ===DONE=== diff --git a/ext/standard/tests/array/range_errors.phpt b/ext/standard/tests/array/range_errors.phpt index bd297945027f0..971eade4bef36 100644 --- a/ext/standard/tests/array/range_errors.phpt +++ b/ext/standard/tests/array/range_errors.phpt @@ -7,37 +7,82 @@ precision=14 echo "\n*** Testing error conditions ***\n"; -echo "\n-- Testing ( (low < high) && (step = 0) ) --"; -var_dump( range(1, 2, 0) ); -var_dump( range("a", "b", 0) ); +echo "\n-- Testing ( (low < high) && (step = 0) ) --\n"; +try { + var_dump( range(1, 2, 0) ); +} catch (\Error $e) { + echo $e->getMessage(), "\n"; +} -echo "\n\n-- Testing ( (low > high) && (step = 0) ) --"; -var_dump( range(2, 1, 0) ); -var_dump( range("b", "a", 0) ); +try { + var_dump( range("a", "b", 0) ); +} catch (\Error $e) { + echo $e->getMessage(), "\n"; +} -echo "\n\n-- Testing ( (low < high) && (high-low < step) ) --"; -var_dump( range(1.0, 7.0, 6.5) ); +echo "\n\n-- Testing ( (low > high) && (step = 0) ) --\n"; +try { + var_dump( range(2, 1, 0) ); +} catch (\Error $e) { + echo $e->getMessage(), "\n"; +} -echo "\n\n-- Testing ( (low > high) && (low-high < step) ) --"; -var_dump( range(7.0, 1.0, 6.5) ); +try { + var_dump( range("b", "a", 0) ); +} catch (\Error $e) { + echo $e->getMessage(), "\n"; +} + +echo "\n\n-- Testing ( (low < high) && (high-low < step) ) --\n"; +try { + var_dump( range(1.0, 7.0, 6.5) ); +} catch (\Error $e) { + echo $e->getMessage(), "\n"; +} + +echo "\n\n-- Testing ( (low > high) && (low-high < step) ) --\n"; +try { + var_dump( range(7.0, 1.0, 6.5) ); +} catch (\Error $e) { + echo $e->getMessage(), "\n"; +} + +echo "\n-- Testing other conditions --\n"; +try { + var_dump( range(-1, -2, 2) ); +} catch (\Error $e) { + echo $e->getMessage(), "\n"; +} -echo "\n-- Testing other conditions --"; -var_dump( range(-1, -2, 2) ); try { var_dump( range("a", "j", "z") ); } catch (TypeError $e) { echo $e->getMessage(), "\n"; +} catch (\Error $e) { + echo $e->getMessage(), "\n"; +} + +try { + var_dump( range(0, 1, "140962482048819216326.24") ); +} catch (\Error $e) { + echo $e->getMessage(), "\n"; +} + +try { + var_dump( range(0, 1, "140962482048819216326.24.") ); +} catch (\Error $e) { + echo $e->getMessage(), "\n"; } -var_dump( range(0, 1, "140962482048819216326.24") ); -var_dump( range(0, 1, "140962482048819216326.24.") ); -echo "\n-- Testing Invalid steps --"; +echo "\n-- Testing Invalid steps --\n"; $step_arr = array( "string", NULL, FALSE, "", "\0" ); foreach( $step_arr as $step ) { try { var_dump( range( 1, 5, $step ) ); - } catch (TypeError $e) { + } catch (\TypeError $e) { + echo $e->getMessage(), "\n"; + } catch (\Error $e) { echo $e->getMessage(), "\n"; } } @@ -48,50 +93,34 @@ echo "Done\n"; *** Testing error conditions *** -- Testing ( (low < high) && (step = 0) ) -- -Warning: range(): step exceeds the specified range in %s on line %d -bool(false) - -Warning: range(): step exceeds the specified range in %s on line %d -bool(false) +step exceeds the specified range +step exceeds the specified range -- Testing ( (low > high) && (step = 0) ) -- -Warning: range(): step exceeds the specified range in %s on line %d -bool(false) - -Warning: range(): step exceeds the specified range in %s on line %d -bool(false) +step exceeds the specified range +step exceeds the specified range -- Testing ( (low < high) && (high-low < step) ) -- -Warning: range(): step exceeds the specified range in %s on line %d -bool(false) +step exceeds the specified range -- Testing ( (low > high) && (low-high < step) ) -- -Warning: range(): step exceeds the specified range in %s on line %d -bool(false) +step exceeds the specified range -- Testing other conditions -- -Warning: range(): step exceeds the specified range in %s on line %d -bool(false) +step exceeds the specified range range() expects parameter 3 to be int or float, string given - -Warning: range(): step exceeds the specified range in %s on line %d -bool(false) +step exceeds the specified range Notice: A non well formed numeric value encountered in %s on line %d +step exceeds the specified range -Warning: range(): step exceeds the specified range in %s on line %d -bool(false) - --- Testing Invalid steps --range() expects parameter 3 to be int or float, string given - -Warning: range(): step exceeds the specified range in %s on line %d -bool(false) - -Warning: range(): step exceeds the specified range in %s on line %d -bool(false) +-- Testing Invalid steps -- +range() expects parameter 3 to be int or float, string given +step exceeds the specified range +step exceeds the specified range range() expects parameter 3 to be int or float, string given range() expects parameter 3 to be int or float, string given Done diff --git a/ext/standard/tests/array/sizeof_basic1.phpt b/ext/standard/tests/array/sizeof_basic1.phpt index c292199cb9d19..b144b14efdd05 100644 --- a/ext/standard/tests/array/sizeof_basic1.phpt +++ b/ext/standard/tests/array/sizeof_basic1.phpt @@ -20,53 +20,72 @@ $floatval = 10.5; $stringval = "String"; echo "-- Testing sizeof() for integer type in default, COUNT_NORMAL and COUNT_RECURSIVE modes --\n"; + echo "default mode: "; -var_dump( sizeof($intval) ); +try { + var_dump( sizeof($intval) ); +} catch (\TypeError $e) { + echo $e->getMessage() . "\n"; +} echo "\n"; + echo "COUNT_NORMAL mode: "; -var_dump( sizeof($intval, COUNT_NORMAL) ); +try { + var_dump( sizeof($intval, COUNT_NORMAL) ); +} catch (\TypeError $e) { + echo $e->getMessage() . "\n"; +} echo "\n"; + echo "COUNT_RECURSIVE mode: "; -var_dump( sizeof($intval, COUNT_RECURSIVE) ); +try { + var_dump( sizeof($intval, COUNT_RECURSIVE) ); +} catch (\TypeError $e) { + echo $e->getMessage() . "\n"; +} echo "\n"; echo "-- Testing sizeof() for float type in default, COUNT_NORMAL and COUNT_RECURSIVE modes --\n"; + echo "default mode: "; -var_dump( sizeof($floatval) ); +try { + var_dump( sizeof($floatval) ); +} catch (\TypeError $e) { + echo $e->getMessage() . "\n"; +} echo "\n"; + echo "COUNT_NORMAL mode: "; -var_dump( sizeof($floatval, COUNT_NORMAL) ); +try { + var_dump( sizeof($floatval, COUNT_NORMAL) ); +} catch (\TypeError $e) { + echo $e->getMessage() . "\n"; +} echo "\n"; -echo "COUNT_RECURSIVE mode: "; -var_dump( sizeof($floatval, COUNT_RECURSIVE) ); -echo "Done"; +echo "COUNT_RECURSIVE mode: "; +try { + var_dump( sizeof($floatval, COUNT_RECURSIVE) ); +} catch (\TypeError $e) { + echo $e->getMessage() . "\n"; +} ?> ---EXPECTF-- + +DONE +--EXPECT-- *** Testing sizeof() : basic functionality *** -- Testing sizeof() for integer type in default, COUNT_NORMAL and COUNT_RECURSIVE modes -- -default mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +default mode: Parameter must be an array or an object that implements Countable -COUNT_NORMAL mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_NORMAL mode: Parameter must be an array or an object that implements Countable -COUNT_RECURSIVE mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_RECURSIVE mode: Parameter must be an array or an object that implements Countable -- Testing sizeof() for float type in default, COUNT_NORMAL and COUNT_RECURSIVE modes -- -default mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) - -COUNT_NORMAL mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) - -COUNT_RECURSIVE mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) -Done +default mode: Parameter must be an array or an object that implements Countable + +COUNT_NORMAL mode: Parameter must be an array or an object that implements Countable + +COUNT_RECURSIVE mode: Parameter must be an array or an object that implements Countable + +DONE diff --git a/ext/standard/tests/array/sizeof_object2.phpt b/ext/standard/tests/array/sizeof_object2.phpt index c81018f6358b5..4db89d07f3f93 100644 --- a/ext/standard/tests/array/sizeof_object2.phpt +++ b/ext/standard/tests/array/sizeof_object2.phpt @@ -77,92 +77,75 @@ $objects = array ( $counter = 1; for($i = 0; $i < count($objects); $i++) { - echo "-- Iteration $counter --\n"; - $var = $objects[$i]; - - echo "Default Mode: "; - var_dump( sizeof($var) ); - echo "\n"; - - echo "COUNT_NORMAL Mode: "; - var_dump( sizeof($var, COUNT_NORMAL) ); - echo "\n"; - - echo "COUNT_RECURSIVE Mode: "; - var_dump( sizeof($var, COUNT_RECURSIVE) ); - echo "\n"; - - $counter++; + echo "-- Iteration $counter --\n"; + + $value = $objects[$i]; + + echo "Default Mode: "; + try { + var_dump( sizeof($value) ); + } catch (\TypeError $e) { + echo $e->getMessage() . "\n"; + } + echo "\n"; + + echo "COUNT_NORMAL Mode: "; + try { + var_dump( sizeof($value, COUNT_NORMAL) ); + } catch (\TypeError $e) { + echo $e->getMessage() . "\n"; + } + echo "\n"; + + echo "COUNT_RECURSIVE Mode: "; + try { + var_dump( sizeof($value, COUNT_RECURSIVE) ); + } catch (\TypeError $e) { + echo $e->getMessage() . "\n"; + } + echo "\n"; + + $counter++; } echo "Done"; ?> ---EXPECTF-- +--EXPECT-- *** Testing sizeof() : object functionality *** --- Testing sizeof() with objects which doesn't implement Countable interface --- -- Iteration 1 -- -Default Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +Default Mode: Parameter must be an array or an object that implements Countable -COUNT_NORMAL Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_NORMAL Mode: Parameter must be an array or an object that implements Countable -COUNT_RECURSIVE Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_RECURSIVE Mode: Parameter must be an array or an object that implements Countable -- Iteration 2 -- -Default Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +Default Mode: Parameter must be an array or an object that implements Countable -COUNT_NORMAL Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_NORMAL Mode: Parameter must be an array or an object that implements Countable -COUNT_RECURSIVE Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_RECURSIVE Mode: Parameter must be an array or an object that implements Countable -- Iteration 3 -- -Default Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +Default Mode: Parameter must be an array or an object that implements Countable -COUNT_NORMAL Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_NORMAL Mode: Parameter must be an array or an object that implements Countable -COUNT_RECURSIVE Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_RECURSIVE Mode: Parameter must be an array or an object that implements Countable -- Iteration 4 -- -Default Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +Default Mode: Parameter must be an array or an object that implements Countable -COUNT_NORMAL Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_NORMAL Mode: Parameter must be an array or an object that implements Countable -COUNT_RECURSIVE Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_RECURSIVE Mode: Parameter must be an array or an object that implements Countable -- Iteration 5 -- -Default Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +Default Mode: Parameter must be an array or an object that implements Countable -COUNT_NORMAL Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_NORMAL Mode: Parameter must be an array or an object that implements Countable -COUNT_RECURSIVE Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_RECURSIVE Mode: Parameter must be an array or an object that implements Countable Done diff --git a/ext/standard/tests/array/sizeof_variation1.phpt b/ext/standard/tests/array/sizeof_variation1.phpt index e98c334267111..5dd469fcbd4a7 100644 --- a/ext/standard/tests/array/sizeof_variation1.phpt +++ b/ext/standard/tests/array/sizeof_variation1.phpt @@ -55,275 +55,173 @@ $values = array ( $counter = 1; for($i = 0; $i < count($values); $i++) { - echo "-- Iteration $counter --\n"; - - $var = $values[$i]; - - echo "Default Mode: "; - var_dump( sizeof($var) ); - echo "\n"; - - echo "COUNT_NORMAL Mode: "; - var_dump( sizeof($var, COUNT_NORMAL) ); - echo "\n"; - - echo "COUNT_RECURSIVE Mode: "; - var_dump( sizeof($var, COUNT_RECURSIVE) ); - echo "\n"; - - $counter++; + echo "-- Iteration $counter --\n"; + + $value = $values[$i]; + + echo "Default Mode: "; + try { + var_dump( sizeof($value) ); + } catch (\TypeError $e) { + echo $e->getMessage() . "\n"; + } + echo "\n"; + + echo "COUNT_NORMAL Mode: "; + try { + var_dump( sizeof($value, COUNT_NORMAL) ); + } catch (\TypeError $e) { + echo $e->getMessage() . "\n"; + } + echo "\n"; + + echo "COUNT_RECURSIVE Mode: "; + try { + var_dump( sizeof($value, COUNT_RECURSIVE) ); + } catch (\TypeError $e) { + echo $e->getMessage() . "\n"; + } + echo "\n"; + + $counter++; } echo "Done"; ?> ---EXPECTF-- +--EXPECT-- *** Testing sizeof() : usage variations *** --- Testing sizeof() for all scalar types in default,COUNT_NORMAL and COUNT_RECURSIVE mode --- -- Iteration 1 -- -Default Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +Default Mode: Parameter must be an array or an object that implements Countable -COUNT_NORMAL Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_NORMAL Mode: Parameter must be an array or an object that implements Countable -COUNT_RECURSIVE Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_RECURSIVE Mode: Parameter must be an array or an object that implements Countable -- Iteration 2 -- -Default Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +Default Mode: Parameter must be an array or an object that implements Countable -COUNT_NORMAL Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_NORMAL Mode: Parameter must be an array or an object that implements Countable -COUNT_RECURSIVE Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_RECURSIVE Mode: Parameter must be an array or an object that implements Countable -- Iteration 3 -- -Default Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +Default Mode: Parameter must be an array or an object that implements Countable -COUNT_NORMAL Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_NORMAL Mode: Parameter must be an array or an object that implements Countable -COUNT_RECURSIVE Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_RECURSIVE Mode: Parameter must be an array or an object that implements Countable -- Iteration 4 -- -Default Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +Default Mode: Parameter must be an array or an object that implements Countable -COUNT_NORMAL Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_NORMAL Mode: Parameter must be an array or an object that implements Countable -COUNT_RECURSIVE Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_RECURSIVE Mode: Parameter must be an array or an object that implements Countable -- Iteration 5 -- -Default Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +Default Mode: Parameter must be an array or an object that implements Countable -COUNT_NORMAL Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_NORMAL Mode: Parameter must be an array or an object that implements Countable -COUNT_RECURSIVE Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_RECURSIVE Mode: Parameter must be an array or an object that implements Countable -- Iteration 6 -- -Default Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +Default Mode: Parameter must be an array or an object that implements Countable -COUNT_NORMAL Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_NORMAL Mode: Parameter must be an array or an object that implements Countable -COUNT_RECURSIVE Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_RECURSIVE Mode: Parameter must be an array or an object that implements Countable -- Iteration 7 -- -Default Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +Default Mode: Parameter must be an array or an object that implements Countable -COUNT_NORMAL Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_NORMAL Mode: Parameter must be an array or an object that implements Countable -COUNT_RECURSIVE Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_RECURSIVE Mode: Parameter must be an array or an object that implements Countable -- Iteration 8 -- -Default Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Default Mode: Parameter must be an array or an object that implements Countable -COUNT_NORMAL Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +COUNT_NORMAL Mode: Parameter must be an array or an object that implements Countable -COUNT_RECURSIVE Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +COUNT_RECURSIVE Mode: Parameter must be an array or an object that implements Countable -- Iteration 9 -- -Default Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Default Mode: Parameter must be an array or an object that implements Countable -COUNT_NORMAL Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +COUNT_NORMAL Mode: Parameter must be an array or an object that implements Countable -COUNT_RECURSIVE Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +COUNT_RECURSIVE Mode: Parameter must be an array or an object that implements Countable -- Iteration 10 -- -Default Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +Default Mode: Parameter must be an array or an object that implements Countable -COUNT_NORMAL Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_NORMAL Mode: Parameter must be an array or an object that implements Countable -COUNT_RECURSIVE Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_RECURSIVE Mode: Parameter must be an array or an object that implements Countable -- Iteration 11 -- -Default Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +Default Mode: Parameter must be an array or an object that implements Countable -COUNT_NORMAL Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_NORMAL Mode: Parameter must be an array or an object that implements Countable -COUNT_RECURSIVE Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_RECURSIVE Mode: Parameter must be an array or an object that implements Countable -- Iteration 12 -- -Default Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +Default Mode: Parameter must be an array or an object that implements Countable -COUNT_NORMAL Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_NORMAL Mode: Parameter must be an array or an object that implements Countable -COUNT_RECURSIVE Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_RECURSIVE Mode: Parameter must be an array or an object that implements Countable -- Iteration 13 -- -Default Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +Default Mode: Parameter must be an array or an object that implements Countable -COUNT_NORMAL Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_NORMAL Mode: Parameter must be an array or an object that implements Countable -COUNT_RECURSIVE Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_RECURSIVE Mode: Parameter must be an array or an object that implements Countable -- Iteration 14 -- -Default Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +Default Mode: Parameter must be an array or an object that implements Countable -COUNT_NORMAL Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_NORMAL Mode: Parameter must be an array or an object that implements Countable -COUNT_RECURSIVE Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_RECURSIVE Mode: Parameter must be an array or an object that implements Countable -- Iteration 15 -- -Default Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +Default Mode: Parameter must be an array or an object that implements Countable -COUNT_NORMAL Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_NORMAL Mode: Parameter must be an array or an object that implements Countable -COUNT_RECURSIVE Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_RECURSIVE Mode: Parameter must be an array or an object that implements Countable -- Iteration 16 -- -Default Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +Default Mode: Parameter must be an array or an object that implements Countable -COUNT_NORMAL Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_NORMAL Mode: Parameter must be an array or an object that implements Countable -COUNT_RECURSIVE Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_RECURSIVE Mode: Parameter must be an array or an object that implements Countable -- Iteration 17 -- -Default Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +Default Mode: Parameter must be an array or an object that implements Countable -COUNT_NORMAL Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_NORMAL Mode: Parameter must be an array or an object that implements Countable -COUNT_RECURSIVE Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_RECURSIVE Mode: Parameter must be an array or an object that implements Countable -- Iteration 18 -- -Default Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Default Mode: Parameter must be an array or an object that implements Countable -COUNT_NORMAL Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +COUNT_NORMAL Mode: Parameter must be an array or an object that implements Countable -COUNT_RECURSIVE Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +COUNT_RECURSIVE Mode: Parameter must be an array or an object that implements Countable -- Iteration 19 -- -Default Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +Default Mode: Parameter must be an array or an object that implements Countable -COUNT_NORMAL Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_NORMAL Mode: Parameter must be an array or an object that implements Countable -COUNT_RECURSIVE Mode: -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(1) +COUNT_RECURSIVE Mode: Parameter must be an array or an object that implements Countable -Done +Done \ No newline at end of file diff --git a/ext/standard/tests/array/sizeof_variation4.phpt b/ext/standard/tests/array/sizeof_variation4.phpt index 465b8181745a0..9981d56d2bef7 100644 --- a/ext/standard/tests/array/sizeof_variation4.phpt +++ b/ext/standard/tests/array/sizeof_variation4.phpt @@ -59,25 +59,37 @@ $values = array ( $counter = 1; foreach($values as $value) { - echo "-- Iteration $counter --\n"; - - // unset the variable - unset($value); - - // now check the size of unset variable when different modes are given - echo "Default Mode: "; - var_dump( sizeof($value) ); - echo "\n"; - - echo "COUNT_NORMAL Mode: "; - var_dump( sizeof($value, COUNT_NORMAL) ); - echo "\n"; - - echo "COUNT_RECURSIVE Mode: "; - var_dump( sizeof($value, COUNT_RECURSIVE) ); - echo "\n"; - - $counter++; + echo "-- Iteration $counter --\n"; + + // unset the variable + unset($value); + + // now check the size of unset variable when different modes are given + echo "Default Mode: "; + try { + var_dump( sizeof($value) ); + } catch (\TypeError $e) { + echo $e->getMessage() . "\n"; + } + echo "\n"; + + echo "COUNT_NORMAL Mode: "; + try { + var_dump( sizeof($value, COUNT_NORMAL) ); + } catch (\TypeError $e) { + echo $e->getMessage() . "\n"; + } + echo "\n"; + + echo "COUNT_RECURSIVE Mode: "; + try { + var_dump( sizeof($value, COUNT_RECURSIVE) ); + } catch (\TypeError $e) { + echo $e->getMessage() . "\n"; + } + echo "\n"; + + $counter++; } fclose($fp); @@ -90,381 +102,261 @@ echo "Done"; -- Iteration 1 -- Default Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable COUNT_NORMAL Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable COUNT_RECURSIVE Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable -- Iteration 2 -- Default Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable COUNT_NORMAL Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable COUNT_RECURSIVE Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable -- Iteration 3 -- Default Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable COUNT_NORMAL Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable COUNT_RECURSIVE Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable -- Iteration 4 -- Default Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable COUNT_NORMAL Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable COUNT_RECURSIVE Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable -- Iteration 5 -- Default Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable COUNT_NORMAL Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable COUNT_RECURSIVE Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable -- Iteration 6 -- Default Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable COUNT_NORMAL Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable COUNT_RECURSIVE Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable -- Iteration 7 -- Default Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable COUNT_NORMAL Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable COUNT_RECURSIVE Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable -- Iteration 8 -- Default Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable COUNT_NORMAL Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable COUNT_RECURSIVE Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable -- Iteration 9 -- Default Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable COUNT_NORMAL Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable COUNT_RECURSIVE Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable -- Iteration 10 -- Default Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable COUNT_NORMAL Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable COUNT_RECURSIVE Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable -- Iteration 11 -- Default Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable COUNT_NORMAL Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable COUNT_RECURSIVE Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable -- Iteration 12 -- Default Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable COUNT_NORMAL Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable COUNT_RECURSIVE Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable -- Iteration 13 -- Default Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable COUNT_NORMAL Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable COUNT_RECURSIVE Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable -- Iteration 14 -- Default Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable COUNT_NORMAL Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable COUNT_RECURSIVE Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable -- Iteration 15 -- Default Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable COUNT_NORMAL Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable COUNT_RECURSIVE Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable -- Iteration 16 -- Default Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable COUNT_NORMAL Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable COUNT_RECURSIVE Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable -- Iteration 17 -- Default Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable COUNT_NORMAL Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable COUNT_RECURSIVE Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable -- Iteration 18 -- Default Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable COUNT_NORMAL Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable COUNT_RECURSIVE Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable -- Iteration 19 -- Default Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable COUNT_NORMAL Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable COUNT_RECURSIVE Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable -- Iteration 20 -- Default Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable COUNT_NORMAL Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable COUNT_RECURSIVE Mode: Notice: Undefined variable: value in %s on line %d - -Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d -int(0) +Parameter must be an array or an object that implements Countable Done diff --git a/run-tests.php b/run-tests.php index 2104ab2a64cae..c9521815d2516 100755 --- a/run-tests.php +++ b/run-tests.php @@ -1861,8 +1861,11 @@ function run_test($php, $file, $env) } } else { - - if (!isset($section_text['PHPDBG']) && @count($section_text['FILE']) + @count($section_text['FILEEOF']) + @count($section_text['FILE_EXTERNAL']) != 1) { + $countFileSection = 0; + if (array_key_exists('FILE', $section_text)) { $countFileSection++; } + if (array_key_exists('FILEEOF', $section_text)) { $countFileSection++; } + if (array_key_exists('FILE_EXTERNAL', $section_text)) { $countFileSection++; } + if (!array_key_exists('PHPDBG', $section_text) && $countFileSection !== 1) { $bork_info = "missing section --FILE--"; } @@ -1887,7 +1890,11 @@ function run_test($php, $file, $env) } } - if ((@count($section_text['EXPECT']) + @count($section_text['EXPECTF']) + @count($section_text['EXPECTREGEX'])) != 1) { + $countExpectSection = 0; + if (array_key_exists('EXPECT', $section_text)) { $countExpectSection++; } + if (array_key_exists('EXPECTF', $section_text)) { $countExpectSection++; } + if (array_key_exists('EXPECTREGEX', $section_text)) { $countExpectSection++; } + if ($countExpectSection !== 1) { $bork_info = "missing section --EXPECT--, --EXPECTF-- or --EXPECTREGEX--"; } } @@ -2244,7 +2251,7 @@ function run_test($php, $file, $env) } } - if (is_array($org_file) || @count($section_text['REDIRECTTEST']) == 1) { + if (is_array($org_file) || array_key_exists('REDIRECTTEST', $section_text) == 1) { if (is_array($org_file)) { $file = $org_file[0]; From b0a2289731a449bfe4400ef2817e07a9089aa9b6 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Tue, 20 Aug 2019 15:36:05 +0200 Subject: [PATCH 2/4] Fix tests and hopefully memleak --- Zend/tests/generators/errors/count_error.phpt | 8 +++++--- ext/standard/array.c | 3 ++- .../is_countable_with_variables.phpt | 12 ++++++++---- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Zend/tests/generators/errors/count_error.phpt b/Zend/tests/generators/errors/count_error.phpt index 97e03e7d712d2..e102ea5b06bef 100644 --- a/Zend/tests/generators/errors/count_error.phpt +++ b/Zend/tests/generators/errors/count_error.phpt @@ -11,8 +11,10 @@ try { count($gen); } catch (Exception $e) { echo $e; -} +} catch (\TypeError $e) { + echo $e->getMessage() . "\n"; + } ?> ---EXPECTF-- -Warning: count(): Parameter must be an array or an object that implements Countable in %s on line %d +--EXPECT-- +Parameter must be an array or an object that implements Countable diff --git a/ext/standard/array.c b/ext/standard/array.c index 432cc48c390f6..56ef5b9b82027 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -1449,7 +1449,8 @@ static int php_array_walk(zval *array, zval *userdata, int recursive) /* {{{ */ pos = zend_hash_iterator_pos(ht_iter, target_hash); } else { zend_type_error("Iterated value is no longer an array or object"); - return -1; + result = FAILURE; + break; } } while (!EG(exception)); diff --git a/ext/standard/tests/general_functions/is_countable_with_variables.phpt b/ext/standard/tests/general_functions/is_countable_with_variables.phpt index 0cb18769d64b8..d48f249ae34b5 100644 --- a/ext/standard/tests/general_functions/is_countable_with_variables.phpt +++ b/ext/standard/tests/general_functions/is_countable_with_variables.phpt @@ -6,7 +6,12 @@ Gabriel Caruso (carusogabriel34@gmail.com) getMessage() . "\n"; +} $foo = ['', []]; @@ -19,10 +24,9 @@ if (!is_countable($bar)) { count($bar); } ?> ---EXPECTF-- +--EXPECT-- bool(true) bool(true) bool(false) int(2) - -Warning: count(): Parameter must be an array or an object that implements Countable in %s on line %d +Parameter must be an array or an object that implements Countable From ff9c0d7d89ecd38b3e6527690042060604e9f832 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Tue, 20 Aug 2019 15:37:28 +0200 Subject: [PATCH 3/4] Fix FFI test (may need changes to FFI?) --- ext/ffi/tests/008.phpt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/ffi/tests/008.phpt b/ext/ffi/tests/008.phpt index 626b2890ce214..8d42c00b5fdd9 100644 --- a/ext/ffi/tests/008.phpt +++ b/ext/ffi/tests/008.phpt @@ -16,7 +16,7 @@ foreach ($a as $key => $val) { $a = FFI::new("struct {int x,y;}"); try { - var_dump(@count($a)); + var_dump(count($a)); } catch (Throwable $e) { echo get_class($e) . ": " . $e->getMessage()."\n"; } @@ -34,5 +34,5 @@ int(3) 0 => 0 1 => 10 2 => 20 -FFI\Exception: Attempt to count() on non C array +TypeError: Parameter must be an array or an object that implements Countable FFI\Exception: Attempt to iterate on non C array From 5e43ac15ca7cc3549f75e461eaf89e88aead1ced Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Tue, 20 Aug 2019 16:01:46 +0200 Subject: [PATCH 4/4] Fix test because I applied the try catch on the wrong bit --- .../is_countable_with_variables.phpt | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/ext/standard/tests/general_functions/is_countable_with_variables.phpt b/ext/standard/tests/general_functions/is_countable_with_variables.phpt index d48f249ae34b5..c23cae266c878 100644 --- a/ext/standard/tests/general_functions/is_countable_with_variables.phpt +++ b/ext/standard/tests/general_functions/is_countable_with_variables.phpt @@ -6,12 +6,7 @@ Gabriel Caruso (carusogabriel34@gmail.com) getMessage() . "\n"; -} +var_dump(is_countable((object) ['foo', 'bar', 'baz'])); $foo = ['', []]; @@ -21,7 +16,11 @@ if (is_countable($foo)) { $bar = null; if (!is_countable($bar)) { - count($bar); + try { + count($bar); + } catch (\TypeError $e) { + echo $e->getMessage() . "\n"; + } } ?> --EXPECT--