Re: instanceof survives non-object variables, but crashes on non-object constants.
| From: | Stanislav Malyshev | Date: | Sat, 09 Dec 2017 23:09:28 +0000 |
| Subject: | Re: instanceof survives non-object variables, but crashes on non-object constants. | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-101285@lists.php.net to get a copy of this message | ||
Hi!
> t think this behavior is inconsistent, and we should consider changing it.
>
> There are two options, but only one is BC.
>
> - Let 1 instanceof \stdClass return false, instead of crashing. -> seems BC
> - Let $x instanceof \stdClass crash, if $x is not an object. -> BC break.
Neither of those "crashes", one of them returns fatal error, which is a
valid option for code that is obviously broken. It would also be a valid
option to return false, but since it is a valid outcome either way, I
don't think changing anything is necessary. It does not make any real
code easier to write (I can't see any legit reason to test numerics for
being instance of anything) and does not improve anything but abstract
"consistency", which in this case is not useful for anything.
--
Stas Malyshev
smalyshev@gmail.com