Re: instanceof survives non-object variables, but crashes on non-object constants.
| From: | Levi Morrison | Date: | Sat, 09 Dec 2017 19:05:41 +0000 |
| Subject: | Re: 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-101283@lists.php.net to get a copy of this message | ||
On Fri, Dec 8, 2017 at 11:35 PM, Kalle Sommer Nielsen <kalle@php.net> wrote:
> We should just add a warning to the first example, it seems like an
> oversight that it was left silent
I strongly object! We ought to consider using
instanceof to support
more type-checks than just classes. I think 1 instanceof int really
ought to return true for both literals and if they were variables:
$lhs = 1;
$rhs = 'int';
var_export($lhs instanceof $rhs);
The fact we do not have a single, unified way to check if some value
on the LHS is of the type on the RHS really bothers me.