RE: [PHP-DEV] instanceof survives non-object variables, but crashes on non-object constants.
| From: | Zeev Suraski | Date: | Sun, 10 Dec 2017 06:37:10 +0000 |
| Subject: | RE: [PHP-DEV] instanceof survives non-object variables, but crashes on non-object constants. | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-101288@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: php@golemon.com [mailto:php@golemon.com] On Behalf Of Sara
> Golemon
> Sent: Sunday, December 10, 2017 1:50 AM
> To: Andreas Hennings <andreas@dqxtech.net>
> Cc: PHP internals <internals@lists.php.net>
> Subject: Re: [PHP-DEV] instanceof survives non-object variables, but crashes
> on non-object constants.
>
> On Sat, Dec 9, 2017 at 1:28 AM, Andreas Hennings <andreas@dqxtech.net>
> wrote:
> > The following (https://3v4l.org/A2Tp6) is ok, it simply returns false:
> >
> > $x = 1;
> > $x instanceof \stdClass;
> >
> >
> > The following (https://3v4l.org/IdSBu) gives a fatal error:
> >
> > 1 instanceof \stdclass;
> >
> > t think this behavior is inconsistent, and we should consider changing it.
> >
> > There is one option, and it is BC.
> >
> > - Let 1 instanceof \stdClass return false, instead of crashing. ->
> > seems BC
> >
> This. There's nothing undefinable about "1 instanceof \stdClass", the clear
> and obvious answer is: "No, it's not an instance of \stdClass, it's an
> integer."
> The runtime result of false makes sense, the compile time error doesn't.
> Let's relax the compile time error (fold it into a const false if you truly must)
> and call it done. There's no need to be hostile to users just because the code
> *seems* silly.
+1
Zeev