diff --git a/Zend/tests/generators/errors/count_error.phpt b/Zend/tests/generators/errors/count_error.phpt index 2eacfd0d359ea..b88902d841c18 100644 --- a/Zend/tests/generators/errors/count_error.phpt +++ b/Zend/tests/generators/errors/count_error.phpt @@ -9,10 +9,10 @@ $gen = gen(); try { count($gen); -} catch (Exception $e) { - echo $e; +} catch (\TypeError $e) { + echo $e->getMessage(), PHP_EOL; } ?> ---EXPECTF-- -Warning: count(): Argument #1 ($var) must be of type Countable|array, Generator given in %s on line %d +--EXPECT-- +count(): Argument #1 ($var) must be of type Countable|array, Generator given diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index 9e10721265ff8..1c06bb42e91c0 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -8883,6 +8883,7 @@ ZEND_VM_COLD_CONST_HANDLER(190, ZEND_COUNT, CONST|TMPVAR|CV, UNUSED) SAVE_OPLINE(); op1 = GET_OP1_ZVAL_PTR_UNDEF(BP_VAR_R); + while (1) { if (Z_TYPE_P(op1) == IS_ARRAY) { count = zend_array_count(Z_ARRVAL_P(op1)); @@ -8911,20 +8912,15 @@ ZEND_VM_COLD_CONST_HANDLER(190, ZEND_COUNT, CONST|TMPVAR|CV, UNUSED) break; } - /* If There's no handler and it doesn't implement Countable then add a warning */ - count = 1; + /* If There's no handler and it doesn't implement Countable then emit a TypeError */ } else if ((OP1_TYPE & (IS_VAR|IS_CV)) != 0 && Z_TYPE_P(op1) == IS_REFERENCE) { op1 = Z_REFVAL_P(op1); continue; - } else if (Z_TYPE_P(op1) <= IS_NULL) { - if (OP1_TYPE == IS_CV && UNEXPECTED(Z_TYPE_P(op1) == IS_UNDEF)) { - ZVAL_UNDEFINED_OP1(); - } - count = 0; - } else { - count = 1; + } else if (OP1_TYPE == IS_CV && UNEXPECTED(Z_TYPE_P(op1) == IS_UNDEF)) { + ZVAL_UNDEFINED_OP1(); } - zend_error(E_WARNING, "%s(): Argument #1 ($var) must be of type Countable|array, %s given", opline->extended_value ? "sizeof" : "count", zend_zval_type_name(op1)); + count = 0; + zend_type_error("%s(): Argument #1 ($var) must be of type Countable|array, %s given", opline->extended_value ? "sizeof" : "count", zend_zval_type_name(op1)); break; } diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index ac0dd911c001c..f43fc024b9c31 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -10324,6 +10324,7 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_CONST_ SAVE_OPLINE(); op1 = RT_CONSTANT(opline, opline->op1); + while (1) { if (Z_TYPE_P(op1) == IS_ARRAY) { count = zend_array_count(Z_ARRVAL_P(op1)); @@ -10352,20 +10353,15 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_CONST_ break; } - /* If There's no handler and it doesn't implement Countable then add a warning */ - count = 1; + /* If There's no handler and it doesn't implement Countable then emit a TypeError */ } else if ((IS_CONST & (IS_VAR|IS_CV)) != 0 && Z_TYPE_P(op1) == IS_REFERENCE) { op1 = Z_REFVAL_P(op1); continue; - } else if (Z_TYPE_P(op1) <= IS_NULL) { - if (IS_CONST == IS_CV && UNEXPECTED(Z_TYPE_P(op1) == IS_UNDEF)) { - ZVAL_UNDEFINED_OP1(); - } - count = 0; - } else { - count = 1; + } else if (IS_CONST == IS_CV && UNEXPECTED(Z_TYPE_P(op1) == IS_UNDEF)) { + ZVAL_UNDEFINED_OP1(); } - zend_error(E_WARNING, "%s(): Argument #1 ($var) must be of type Countable|array, %s given", opline->extended_value ? "sizeof" : "count", zend_zval_type_name(op1)); + count = 0; + zend_type_error("%s(): Argument #1 ($var) must be of type Countable|array, %s given", opline->extended_value ? "sizeof" : "count", zend_zval_type_name(op1)); break; } @@ -17567,6 +17563,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_TMPVAR_UNUSED_HANDL SAVE_OPLINE(); op1 = _get_zval_ptr_var(opline->op1.var EXECUTE_DATA_CC); + while (1) { if (Z_TYPE_P(op1) == IS_ARRAY) { count = zend_array_count(Z_ARRVAL_P(op1)); @@ -17595,20 +17592,15 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_TMPVAR_UNUSED_HANDL break; } - /* If There's no handler and it doesn't implement Countable then add a warning */ - count = 1; + /* If There's no handler and it doesn't implement Countable then emit a TypeError */ } else if (((IS_TMP_VAR|IS_VAR) & (IS_VAR|IS_CV)) != 0 && Z_TYPE_P(op1) == IS_REFERENCE) { op1 = Z_REFVAL_P(op1); continue; - } else if (Z_TYPE_P(op1) <= IS_NULL) { - if ((IS_TMP_VAR|IS_VAR) == IS_CV && UNEXPECTED(Z_TYPE_P(op1) == IS_UNDEF)) { - ZVAL_UNDEFINED_OP1(); - } - count = 0; - } else { - count = 1; + } else if ((IS_TMP_VAR|IS_VAR) == IS_CV && UNEXPECTED(Z_TYPE_P(op1) == IS_UNDEF)) { + ZVAL_UNDEFINED_OP1(); } - zend_error(E_WARNING, "%s(): Argument #1 ($var) must be of type Countable|array, %s given", opline->extended_value ? "sizeof" : "count", zend_zval_type_name(op1)); + count = 0; + zend_type_error("%s(): Argument #1 ($var) must be of type Countable|array, %s given", opline->extended_value ? "sizeof" : "count", zend_zval_type_name(op1)); break; } @@ -47327,6 +47319,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_CV_UNUSED_HANDLER(Z SAVE_OPLINE(); op1 = EX_VAR(opline->op1.var); + while (1) { if (Z_TYPE_P(op1) == IS_ARRAY) { count = zend_array_count(Z_ARRVAL_P(op1)); @@ -47355,20 +47348,15 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_CV_UNUSED_HANDLER(Z break; } - /* If There's no handler and it doesn't implement Countable then add a warning */ - count = 1; + /* If There's no handler and it doesn't implement Countable then emit a TypeError */ } else if ((IS_CV & (IS_VAR|IS_CV)) != 0 && Z_TYPE_P(op1) == IS_REFERENCE) { op1 = Z_REFVAL_P(op1); continue; - } else if (Z_TYPE_P(op1) <= IS_NULL) { - if (IS_CV == IS_CV && UNEXPECTED(Z_TYPE_P(op1) == IS_UNDEF)) { - ZVAL_UNDEFINED_OP1(); - } - count = 0; - } else { - count = 1; + } else if (IS_CV == IS_CV && UNEXPECTED(Z_TYPE_P(op1) == IS_UNDEF)) { + ZVAL_UNDEFINED_OP1(); } - zend_error(E_WARNING, "%s(): Argument #1 ($var) must be of type Countable|array, %s given", opline->extended_value ? "sizeof" : "count", zend_zval_type_name(op1)); + count = 0; + zend_type_error("%s(): Argument #1 ($var) must be of type Countable|array, %s given", opline->extended_value ? "sizeof" : "count", zend_zval_type_name(op1)); break; } diff --git a/ext/standard/array.c b/ext/standard/array.c index bd2823a4076ca..f99af846114dd 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -740,11 +740,6 @@ PHP_FUNCTION(count) } switch (Z_TYPE_P(array)) { - case IS_NULL: - /* Intentionally not converted to an exception */ - php_error_docref(NULL, E_WARNING, "%s(): Argument #1 ($var) must be of type Countable|array, %s given", get_active_function_name(), zend_zval_type_name(array)); - RETURN_LONG(0); - break; case IS_ARRAY: if (mode != COUNT_RECURSIVE) { cnt = zend_array_count(Z_ARRVAL_P(array)); @@ -774,18 +769,11 @@ PHP_FUNCTION(count) } return; } - - /* If There's no handler and it doesn't implement Countable then add a warning */ - /* Intentionally not converted to an exception */ - php_error_docref(NULL, E_WARNING, "%s(): Argument #1 ($var) must be of type Countable|array, %s given", get_active_function_name(), zend_zval_type_name(array)); - RETURN_LONG(1); - break; } + /* fallthrough */ default: - /* Intentionally not converted to an exception */ - php_error_docref(NULL, E_WARNING, "%s(): Argument #1 ($var) must be of type Countable|array, %s given", get_active_function_name(), zend_zval_type_name(array)); - RETURN_LONG(1); - break; + zend_argument_type_error(1, "must be of type Countable|array, %s given", zend_zval_type_name(array)); + RETURN_THROWS(); } } /* }}} */ diff --git a/ext/standard/tests/array/count_invalid.phpt b/ext/standard/tests/array/count_invalid.phpt index 4b146de85b933..b4fb27c8a967b 100644 --- a/ext/standard/tests/array/count_invalid.phpt +++ b/ext/standard/tests/array/count_invalid.phpt @@ -3,40 +3,54 @@ Only arrays and countable objects can be counted --FILE-- getMessage() . \PHP_EOL; +} + +try { + $result = count("string"); + var_dump($result); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} + +try { + $result = count(123); + var_dump($result); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} + +try { + $result = count(true); + var_dump($result); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} + +try { + $result = count(false); + var_dump($result); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} + +try { + $result = count((object) []); + var_dump($result); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} ?> ---EXPECTF-- -Warning: count(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -Warning: count(): Argument #1 ($var) must be of type Countable|array, string given in %s on line %d -int(1) - -Warning: count(): Argument #1 ($var) must be of type Countable|array, int given in %s on line %d -int(1) - -Warning: count(): Argument #1 ($var) must be of type Countable|array, bool given in %s on line %d -int(1) - -Warning: count(): Argument #1 ($var) must be of type Countable|array, bool given in %s on line %d -int(1) +--EXPECT-- +count(): Argument #1 ($var) must be of type Countable|array, null given +count(): Argument #1 ($var) must be of type Countable|array, string given +count(): Argument #1 ($var) must be of type Countable|array, int given +count(): Argument #1 ($var) must be of type Countable|array, bool given +count(): Argument #1 ($var) must be of type Countable|array, bool given +count(): Argument #1 ($var) must be of type Countable|array, stdClass given -Warning: count(): Argument #1 ($var) must be of type Countable|array, stdClass given in %s on line %d -int(1) diff --git a/ext/standard/tests/array/count_recursive.phpt b/ext/standard/tests/array/count_recursive.phpt index 8532a74cb68ed..321706bc24869 100644 --- a/ext/standard/tests/array/count_recursive.phpt +++ b/ext/standard/tests/array/count_recursive.phpt @@ -3,10 +3,6 @@ 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 "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), @@ -56,18 +47,6 @@ foreach ($count_array as $count_value) { $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"; @@ -111,30 +90,13 @@ closedir( $resource2 ); ?> --EXPECTF-- *** Testing basic functionality of count() function *** --- Testing NULL -- - -Warning: count(): count(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -COUNT_NORMAL: should be 0, is 0 - -Warning: count(): count(): Argument #1 ($var) must be of type Countable|array, null given 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(): count(): Argument #1 ($var) must be of type Countable|array, string given in %s on line %d -COUNT_NORMAL: should be 1, is 1 - -Warning: count(): count(): Argument #1 ($var) must be of type Countable|array, string given in %s on line %d -COUNT_RECURSIVE: should be 1, is 1 -- Testing various types with no second argument -- - -Warning: count(): Argument #1 ($var) must be of type Countable|array, string given in %s on line %d -COUNT_NORMAL: should be 1, is 1 COUNT_NORMAL: should be 2, is 2 -- Testing really cool arrays -- COUNT_NORMAL: should be 3, is 3 @@ -173,23 +135,6 @@ COUNT_RECURSIVE is 6 COUNT_NORMAL is 4 COUNT_RECURSIVE is 7 --- Testing count() on constants with no second argument -- - -Warning: count(): Argument #1 ($var) must be of type Countable|array, int given in %s on line %d -COUNT_NORMAL: should be 1, is 1 - -Warning: count(): Argument #1 ($var) must be of type Countable|array, float given in %s on line %d -COUNT_NORMAL: should be 1, is 1 - --- Testing count() on NULL and Unset variables -- - -Warning: count(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -COUNT_NORMAL: should be 0, is 0 - -Warning: count(): Argument #1 ($var) must be of type Countable|array, string given 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/sizeof_basic1.phpt b/ext/standard/tests/array/sizeof_basic1.phpt deleted file mode 100644 index 4c5910e3570e6..0000000000000 --- a/ext/standard/tests/array/sizeof_basic1.phpt +++ /dev/null @@ -1,65 +0,0 @@ ---TEST-- -Test sizeof() function : basic functionality - for scalar types ---FILE-- - ---EXPECTF-- -*** Testing sizeof() : basic functionality *** --- Testing sizeof() for integer type in default, COUNT_NORMAL and COUNT_RECURSIVE modes -- -default mode: -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, int given in %s on line %d -int(1) - -COUNT_NORMAL mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, int given in %s on line %d -int(1) - -COUNT_RECURSIVE mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, int given in %s on line %d -int(1) - --- Testing sizeof() for float type in default, COUNT_NORMAL and COUNT_RECURSIVE modes -- -default mode: -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, float given in %s on line %d -int(1) - -COUNT_NORMAL mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, float given in %s on line %d -int(1) - -COUNT_RECURSIVE mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, float given in %s on line %d -int(1) -Done diff --git a/ext/standard/tests/array/sizeof_object2.phpt b/ext/standard/tests/array/sizeof_object2.phpt index 9a96719eb68c0..754198765685f 100644 --- a/ext/standard/tests/array/sizeof_object2.phpt +++ b/ext/standard/tests/array/sizeof_object2.phpt @@ -74,88 +74,52 @@ for($i = 0; $i < count($objects); $i++) $var = $objects[$i]; echo "Default Mode: "; - var_dump( sizeof($var) ); - echo "\n"; + try { + var_dump( sizeof($var) ); + } catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; + } echo "COUNT_NORMAL Mode: "; - var_dump( sizeof($var, COUNT_NORMAL) ); - echo "\n"; + try { + var_dump( sizeof($var, COUNT_NORMAL) ); + } catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; + } echo "COUNT_RECURSIVE Mode: "; - var_dump( sizeof($var, COUNT_RECURSIVE) ); - echo "\n"; + try { + var_dump( sizeof($var, COUNT_RECURSIVE) ); + } catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; + } $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(): Argument #1 ($var) must be of type Countable|array, test given in %s on line %d -int(1) - -COUNT_NORMAL Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, test given in %s on line %d -int(1) - -COUNT_RECURSIVE Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, test given in %s on line %d -int(1) - +Default Mode: sizeof(): Argument #1 ($var) must be of type Countable|array, test given +COUNT_NORMAL Mode: sizeof(): Argument #1 ($var) must be of type Countable|array, test given +COUNT_RECURSIVE Mode: sizeof(): Argument #1 ($var) must be of type Countable|array, test given -- Iteration 2 -- -Default Mode: -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, test1 given in %s on line %d -int(1) - -COUNT_NORMAL Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, test1 given in %s on line %d -int(1) - -COUNT_RECURSIVE Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, test1 given in %s on line %d -int(1) - +Default Mode: sizeof(): Argument #1 ($var) must be of type Countable|array, test1 given +COUNT_NORMAL Mode: sizeof(): Argument #1 ($var) must be of type Countable|array, test1 given +COUNT_RECURSIVE Mode: sizeof(): Argument #1 ($var) must be of type Countable|array, test1 given -- Iteration 3 -- -Default Mode: -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, test2 given in %s on line %d -int(1) - -COUNT_NORMAL Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, test2 given in %s on line %d -int(1) - -COUNT_RECURSIVE Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, test2 given in %s on line %d -int(1) - +Default Mode: sizeof(): Argument #1 ($var) must be of type Countable|array, test2 given +COUNT_NORMAL Mode: sizeof(): Argument #1 ($var) must be of type Countable|array, test2 given +COUNT_RECURSIVE Mode: sizeof(): Argument #1 ($var) must be of type Countable|array, test2 given -- Iteration 4 -- -Default Mode: -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, child_test2 given in %s on line %d -int(1) - -COUNT_NORMAL Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, child_test2 given in %s on line %d -int(1) - -COUNT_RECURSIVE Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, child_test2 given in %s on line %d -int(1) - +Default Mode: sizeof(): Argument #1 ($var) must be of type Countable|array, child_test2 given +COUNT_NORMAL Mode: sizeof(): Argument #1 ($var) must be of type Countable|array, child_test2 given +COUNT_RECURSIVE Mode: sizeof(): Argument #1 ($var) must be of type Countable|array, child_test2 given -- Iteration 5 -- -Default Mode: -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, concrete_class given in %s on line %d -int(1) - -COUNT_NORMAL Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, concrete_class given in %s on line %d -int(1) - -COUNT_RECURSIVE Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, concrete_class given in %s on line %d -int(1) - +Default Mode: sizeof(): Argument #1 ($var) must be of type Countable|array, concrete_class given +COUNT_NORMAL Mode: sizeof(): Argument #1 ($var) must be of type Countable|array, concrete_class given +COUNT_RECURSIVE Mode: sizeof(): Argument #1 ($var) must be of type Countable|array, concrete_class given Done diff --git a/ext/standard/tests/array/sizeof_variation1.phpt b/ext/standard/tests/array/sizeof_variation1.phpt deleted file mode 100644 index 13196d3170edb..0000000000000 --- a/ext/standard/tests/array/sizeof_variation1.phpt +++ /dev/null @@ -1,322 +0,0 @@ ---TEST-- -Test sizeof() function : usage variations - for all scalar types and resource variable ---FILE-- - ---EXPECTF-- -*** Testing sizeof() : usage variations *** ---- Testing sizeof() for all scalar types in default,COUNT_NORMAL and COUNT_RECURSIVE mode --- --- Iteration 1 -- -Default Mode: -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, int given in %s on line %d -int(1) - -COUNT_NORMAL Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, int given in %s on line %d -int(1) - -COUNT_RECURSIVE Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, int given in %s on line %d -int(1) - --- Iteration 2 -- -Default Mode: -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, int given in %s on line %d -int(1) - -COUNT_NORMAL Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, int given in %s on line %d -int(1) - -COUNT_RECURSIVE Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, int given in %s on line %d -int(1) - --- Iteration 3 -- -Default Mode: -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, float given in %s on line %d -int(1) - -COUNT_NORMAL Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, float given in %s on line %d -int(1) - -COUNT_RECURSIVE Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, float given in %s on line %d -int(1) - --- Iteration 4 -- -Default Mode: -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, float given in %s on line %d -int(1) - -COUNT_NORMAL Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, float given in %s on line %d -int(1) - -COUNT_RECURSIVE Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, float given in %s on line %d -int(1) - --- Iteration 5 -- -Default Mode: -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, float given in %s on line %d -int(1) - -COUNT_NORMAL Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, float given in %s on line %d -int(1) - -COUNT_RECURSIVE Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, float given in %s on line %d -int(1) - --- Iteration 6 -- -Default Mode: -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, float given in %s on line %d -int(1) - -COUNT_NORMAL Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, float given in %s on line %d -int(1) - -COUNT_RECURSIVE Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, float given in %s on line %d -int(1) - --- Iteration 7 -- -Default Mode: -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, float given in %s on line %d -int(1) - -COUNT_NORMAL Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, float given in %s on line %d -int(1) - -COUNT_RECURSIVE Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, float given in %s on line %d -int(1) - --- Iteration 8 -- -Default Mode: -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_NORMAL Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_RECURSIVE Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - --- Iteration 9 -- -Default Mode: -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_NORMAL Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_RECURSIVE Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - --- Iteration 10 -- -Default Mode: -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, bool given in %s on line %d -int(1) - -COUNT_NORMAL Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, bool given in %s on line %d -int(1) - -COUNT_RECURSIVE Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, bool given in %s on line %d -int(1) - --- Iteration 11 -- -Default Mode: -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, bool given in %s on line %d -int(1) - -COUNT_NORMAL Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, bool given in %s on line %d -int(1) - -COUNT_RECURSIVE Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, bool given in %s on line %d -int(1) - --- Iteration 12 -- -Default Mode: -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, bool given in %s on line %d -int(1) - -COUNT_NORMAL Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, bool given in %s on line %d -int(1) - -COUNT_RECURSIVE Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, bool given in %s on line %d -int(1) - --- Iteration 13 -- -Default Mode: -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, bool given in %s on line %d -int(1) - -COUNT_NORMAL Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, bool given in %s on line %d -int(1) - -COUNT_RECURSIVE Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, bool given in %s on line %d -int(1) - --- Iteration 14 -- -Default Mode: -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, string given in %s on line %d -int(1) - -COUNT_NORMAL Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, string given in %s on line %d -int(1) - -COUNT_RECURSIVE Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, string given in %s on line %d -int(1) - --- Iteration 15 -- -Default Mode: -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, string given in %s on line %d -int(1) - -COUNT_NORMAL Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, string given in %s on line %d -int(1) - -COUNT_RECURSIVE Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, string given in %s on line %d -int(1) - --- Iteration 16 -- -Default Mode: -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, string given in %s on line %d -int(1) - -COUNT_NORMAL Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, string given in %s on line %d -int(1) - -COUNT_RECURSIVE Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, string given in %s on line %d -int(1) - --- Iteration 17 -- -Default Mode: -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, string given in %s on line %d -int(1) - -COUNT_NORMAL Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, string given in %s on line %d -int(1) - -COUNT_RECURSIVE Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, string given in %s on line %d -int(1) - --- Iteration 18 -- -Default Mode: -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_NORMAL Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_RECURSIVE Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - --- Iteration 19 -- -Default Mode: -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, resource given in %s on line %d -int(1) - -COUNT_NORMAL Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, resource given in %s on line %d -int(1) - -COUNT_RECURSIVE Mode: -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, resource given in %s on line %d -int(1) - -Done diff --git a/ext/standard/tests/array/sizeof_variation4.phpt b/ext/standard/tests/array/sizeof_variation4.phpt deleted file mode 100644 index c8484d84512ca..0000000000000 --- a/ext/standard/tests/array/sizeof_variation4.phpt +++ /dev/null @@ -1,463 +0,0 @@ ---TEST-- -Test sizeof() function : usage variations - all kinds of unset variables for 'var' argument ---FILE-- - ---EXPECTF-- -*** Testing sizeof() : usage variations *** ---- Testing sizeof() for all kinds of unset variables in default, Normal and Recursive Modes --- --- Iteration 1 -- -Default Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_NORMAL Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_RECURSIVE Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - --- Iteration 2 -- -Default Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_NORMAL Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_RECURSIVE Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - --- Iteration 3 -- -Default Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_NORMAL Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_RECURSIVE Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - --- Iteration 4 -- -Default Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_NORMAL Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_RECURSIVE Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - --- Iteration 5 -- -Default Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_NORMAL Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_RECURSIVE Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - --- Iteration 6 -- -Default Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_NORMAL Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_RECURSIVE Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - --- Iteration 7 -- -Default Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_NORMAL Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_RECURSIVE Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - --- Iteration 8 -- -Default Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_NORMAL Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_RECURSIVE Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - --- Iteration 9 -- -Default Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_NORMAL Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_RECURSIVE Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - --- Iteration 10 -- -Default Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_NORMAL Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_RECURSIVE Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - --- Iteration 11 -- -Default Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_NORMAL Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_RECURSIVE Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - --- Iteration 12 -- -Default Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_NORMAL Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_RECURSIVE Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - --- Iteration 13 -- -Default Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_NORMAL Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_RECURSIVE Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - --- Iteration 14 -- -Default Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_NORMAL Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_RECURSIVE Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - --- Iteration 15 -- -Default Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_NORMAL Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_RECURSIVE Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - --- Iteration 16 -- -Default Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_NORMAL Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_RECURSIVE Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - --- Iteration 17 -- -Default Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_NORMAL Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_RECURSIVE Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - --- Iteration 18 -- -Default Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_NORMAL Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_RECURSIVE Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - --- Iteration 19 -- -Default Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_NORMAL Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_RECURSIVE Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - --- Iteration 20 -- -Default Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_NORMAL Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -COUNT_RECURSIVE Mode: -Warning: Undefined variable $value in %s on line %d - -Warning: sizeof(): sizeof(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d -int(0) - -Done 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 7a4efc914b27d..01fa0fae6f6f2 100644 --- a/ext/standard/tests/general_functions/is_countable_with_variables.phpt +++ b/ext/standard/tests/general_functions/is_countable_with_variables.phpt @@ -16,13 +16,16 @@ if (is_countable($foo)) { $bar = null; if (!is_countable($bar)) { - count($bar); + try { + count($bar); + } catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; + } } ?> ---EXPECTF-- +--EXPECT-- bool(true) bool(true) bool(false) int(2) - -Warning: count(): Argument #1 ($var) must be of type Countable|array, null given in %s on line %d +count(): Argument #1 ($var) must be of type Countable|array, null given