On Sun, Dec 10, 2017 at 12:09 AM, Stanislav Malyshev <smalys...@gmail.com>
wrote:

> 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.
>

The main issue seems to be that if people are not sure whether they have to
do an is_object() check before using instanceof, they just quickly test it
using "42 instanceof A" and then draw the entirely wrong conclusion from
the generated error. I've certainly seen this play out more than once.

Which is why I'd be in favor of changing instanceof to returning false in
this case.

Nikita

Reply via email to