note 126504 added to language.types.declarations
| From: | HayleyWatson at main dot php dot net | Date: | Thu, 14 Oct 2021 00:18:24 +0000 |
| Subject: | note 126504 added to language.types.declarations | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-217069@lists.php.net to get a copy of this message | ||
Not explicit is that function parameters can also have union type declarations; they're not
just for property and return value declarations.
<?php
declare(strict_types = 1);
function foo(int|string $arg)
{
if(is_string($arg))
{
echo "It's a string!\n";
}
elseif(is_int($arg))
{
echo "It's an integer!\n";
}
else
{
echo "It shouldn't be here!\n";
}
}
foo(42);
foo('bar');
foo([]);
----
Server IP: 45.112.84.4
Probable Submitter: 45.112.85.242 (proxied: 222.153.57.60)
----
Manual Page -- https://php.net/manual/en/language.types.declarations.php
Edit -- https://main.php.net/note/edit/126504
Del: integrated -- https://main.php.net/note/delete/126504/integrated
Del: useless -- https://main.php.net/note/delete/126504/useless
Del: bad code -- https://main.php.net/note/delete/126504/bad+code
Del: spam -- https://main.php.net/note/delete/126504/spam
Del: non-english -- https://main.php.net/note/delete/126504/non-english
Del: in docs -- https://main.php.net/note/delete/126504/in+docs
Del: other reasons-- https://main.php.net/note/delete/126504
Reject -- https://main.php.net/note/reject/126504
Search -- https://main.php.net/manage/user-notes.php