mirror of
https://github.com/php/php-src.git
synced 2026-03-24 16:22:37 +01:00
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.
20 lines
311 B
PHP
20 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!
|