note 127121 added to function.array-merge
| From: | Maks at main dot php dot net | Date: | Sat, 21 May 2022 08:21:40 +0000 |
| Subject: | note 127121 added to function.array-merge | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-218510@lists.php.net to get a copy of this message | ||
Be careful with the return value.
In the "Return Values" section it states the next:
> Returns the resulting array. If called without any arguments, returns an empty array.
By that, we can assume that the result of the function is ALWAYS an array, as there are no other
statements.
Indeed, when one of the values is not an array and the PHP version is < 8.0, it can be NULL and
the "Warning" will be generated. With PHP >= 8.0 it will be a "Fatal error".
<?PHP
foreach ([null, false, ''] as $item) {
$list = array_merge($item, [1, 2]);
echo null === $list ? 'YES' : 'NO'; // It's always YES here
}
?>
----
Server IP: 45.112.84.4
Probable Submitter: 185.85.3.47 (proxied: 188.163.44.2)
----
Manual Page -- https://php.net/manual/en/function.array-merge.php
Edit -- https://main.php.net/note/edit/127121
Del: integrated -- https://main.php.net/note/delete/127121/integrated
Del: useless -- https://main.php.net/note/delete/127121/useless
Del: bad code -- https://main.php.net/note/delete/127121/bad+code
Del: spam -- https://main.php.net/note/delete/127121/spam
Del: non-english -- https://main.php.net/note/delete/127121/non-english
Del: in docs -- https://main.php.net/note/delete/127121/in+docs
Del: other reasons-- https://main.php.net/note/delete/127121
Reject -- https://main.php.net/note/reject/127121
Search -- https://main.php.net/manage/user-notes.php