php-src/ext/standard/tests/array/array_diff_1.phpt
Nikita Popov 73ab7b30ca Allow array_diff() and array_intersect() with single array argument
Both of these functions are well-defined when used with a single
array argument -- rejecting this case was an artificial limitation.
This is not useful when called with explicit arguments, but removes
edge-cases when used with argument unpacking:

    // OK even if $excludes is empty.
    array_diff($array, ...$excludes);

    // OK even if $arrays contains a single array only.
    array_intersect(...$arrays);

This matches the behavior of functions like array_merge() and
array_push(), which also allow calls with no array or a single
array respectively.

Closes GH-6097.
2020-09-09 11:03:17 +02:00

19 lines
311 B
PHP

--TEST--
Test array_diff when non-array is passed
--FILE--
<?php
//-=-=-=-=-
$a = array();
$b = 3;
$c = array(5);
try {
array_diff($a, $b, $c);
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
}
//-=-=-=-=-=-
echo "OK!";
?>
--EXPECT--
array_diff(): Argument #2 must be of type array, int given
OK!