From f885924f764edbe691662c2aa3a209185f7fba12 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Tue, 20 Aug 2019 22:35:00 +0200 Subject: [PATCH] Promote warning to type error in count() --- Zend/tests/generators/errors/count_error.phpt | 8 +- Zend/zend_vm_def.h | 2 +- Zend/zend_vm_execute.h | 6 +- ext/ffi/tests/008.phpt | 4 +- ext/standard/array.c | 8 +- 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/sizeof_basic1.phpt | 79 +++-- ext/standard/tests/array/sizeof_object2.phpt | 107 +++---- .../tests/array/sizeof_variation1.phpt | 278 ++++++----------- .../tests/array/sizeof_variation4.phpt | 290 ++++++------------ .../is_countable_with_variables.phpt | 11 +- run-tests.php | 15 +- 15 files changed, 450 insertions(+), 618 deletions(-) create mode 100644 ext/standard/tests/array/count_errors.phpt 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/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/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 diff --git a/ext/standard/array.c b/ext/standard/array.c index 70523d479ef4f..6645a17891ad8 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,7 +773,7 @@ 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"); + zend_type_error("Parameter must be an array or an object that implements Countable"); RETURN_LONG(0); break; case IS_ARRAY: @@ -804,12 +804,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"); + zend_type_error("Parameter must be an array or an object that implements Countable"); RETURN_LONG(1); break; } default: - php_error_docref(NULL, E_WARNING, "Parameter must be an array or an object that implements Countable"); + zend_type_error("Parameter must be an array or an object that implements Countable"); RETURN_LONG(1); break; } 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/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/ext/standard/tests/general_functions/is_countable_with_variables.phpt b/ext/standard/tests/general_functions/is_countable_with_variables.phpt index 0cb18769d64b8..c23cae266c878 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() . "\n"; + } } ?> ---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 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];