php-src/ext/standard/tests/array/array_walk_recursive_error2.phpt
Dmitry Stogov ff363e2e7c Implemented RFC: Replace "Missing argument" warning with "Too few arguments" exception
Squashed commit of the following:

commit 8b45fa2acb
Author: Dmitry Stogov <dmitry@zend.com>
Date:   Thu Jun 16 01:52:50 2016 +0300

    Separate slow path of ZEND_RECV into a cold function.

commit 9e18895ee5
Author: Dmitry Stogov <dmitry@zend.com>
Date:   Wed Jun 15 23:26:28 2016 +0300

    Required argument can't be IS_UNDEF anymore.

commit 662db66e39
Author: Dmitry Stogov <dmitry@zend.com>
Date:   Tue May 31 17:14:50 2016 +0300

    Replace "Missing argument" warning by "Too few arguments" exception.
2016-06-16 02:32:02 +03:00

67 lines
2.1 KiB
PHP

--TEST--
Test array_walk_recursive() function : error conditions - callback parameters
--FILE--
<?php
/* Prototype : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata])
* Description: Apply a user function to every member of an array
* Source code: ext/standard/array.c
*/
/*
* Testing array_walk_recursive() by passing more number of parameters to callback function
*/
$input = array(1);
function callback1($value, $key, $user_data ) {
echo "\ncallback1() invoked \n";
}
function callback2($value, $key, $user_data1, $user_data2) {
echo "\ncallback2() invoked \n";
}
echo "*** Testing array_walk_recursive() : error conditions - callback parameters ***\n";
// expected: Missing argument Warning
try {
var_dump( array_walk_recursive($input, "callback1") );
} catch (Throwable $e) {
echo "Exception: " . $e->getMessage() . "\n";
}
try {
var_dump( array_walk_recursive($input, "callback2", 4) );
} catch (Throwable $e) {
echo "Exception: " . $e->getMessage() . "\n";
}
// expected: Warning is suppressed
try {
var_dump( @array_walk_recursive($input, "callback1") );
} catch (Throwable $e) {
echo "Exception: " . $e->getMessage() . "\n";
}
try {
var_dump( @array_walk_recursive($input, "callback2", 4) );
} catch (Throwable $e) {
echo "Exception: " . $e->getMessage() . "\n";
}
echo "-- Testing array_walk_recursive() function with too many callback parameters --\n";
try {
var_dump( array_walk_recursive($input, "callback1", 20, 10) );
} catch (Throwable $e) {
echo "Exception: " . $e->getMessage() . "\n";
}
echo "Done";
?>
--EXPECTF--
*** Testing array_walk_recursive() : error conditions - callback parameters ***
Exception: Too few arguments to function callback1(), 2 passed and exactly 3 expected
Exception: Too few arguments to function callback2(), 3 passed and exactly 4 expected
Exception: Too few arguments to function callback1(), 2 passed and exactly 3 expected
Exception: Too few arguments to function callback2(), 3 passed and exactly 4 expected
-- Testing array_walk_recursive() function with too many callback parameters --
Warning: array_walk_recursive() expects at most 3 parameters, 4 given in %s on line %d
NULL
Done