Re: Union type casts
| From: | Claude Pache | Date: | Wed, 05 Oct 2022 08:04:15 +0000 |
| Subject: | Re: Union type casts | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-118748@lists.php.net to get a copy of this message | ||
> Le 5 oct. 2022 à 06:46, Eugene Sidelnyk <zsidelnik@gmail.com> a écrit :
>
> I assume the behavior should be the same as if we called the function
> having respective parameter type-hint (with a remark that strict types are
> disabled):
Hi,
Function parameters are more restrictive than explicit cast in what it accepts. In particular, the
following inputs are rejected with a TypeError when fed to a function that accepts an
int: "3 mices", null, [ ]. Most
notably, no type conversion is performed when the input type is null or
array, or when the target type is array or object.
For reference, the original conversion rules are here: https://wiki.php.net/rfc/union_types_v2#coercive_typing_mode
<https://wiki.php.net/rfc/union_types_v2#coercive_typing_mode>
(I don’t know if there has been adjustments since then.)
—Claude