RE: [PHP-DEV] instanceof survives non-object variables, but crashes on non-object constants.

2017-12-09 Thread Zeev Suraski
> -Original Message- > From: p...@golemon.com [mailto:p...@golemon.com] On Behalf Of Sara > Golemon > Sent: Sunday, December 10, 2017 1:50 AM > To: Andreas Hennings > Cc: PHP internals > Subject: Re: [PHP-DEV] instanceof survives non-object variables, but crashes > on non-object constants

Re: [PHP-DEV] instanceof survives non-object variables, but crashes on non-object constants.

2017-12-09 Thread Sara Golemon
On Sat, Dec 9, 2017 at 1:28 AM, Andreas Hennings 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 behavio

Re: [PHP-DEV] instanceof survives non-object variables, but crashes on non-object constants.

2017-12-09 Thread Nikita Popov
On Sun, Dec 10, 2017 at 12:09 AM, Stanislav Malyshev 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 $

Re: [PHP-DEV] instanceof survives non-object variables, but crashes on non-object constants.

2017-12-09 Thread Stanislav Malyshev
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

Re: [PHP-DEV] instanceof survives non-object variables, but crashes on non-object constants.

2017-12-09 Thread Andreas Hennings
On 9 December 2017 at 16:19, Aidan Woods wrote: > > where the three lines return `false`, the third [...] > > Oops, that should say "the first two lines return `true`, the third > `false`" (the point here being that they return something, as opposed to > the later three, which throw). > > This is

Re: [PHP-DEV] instanceof survives non-object variables, but crashes on non-object constants.

2017-12-09 Thread Levi Morrison
On Fri, Dec 8, 2017 at 11:35 PM, Kalle Sommer Nielsen 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 in

Re: [PHP-DEV] instanceof survives non-object variables, but crashes on non-object constants.

2017-12-09 Thread Aidan Woods
> where the three lines return `false`, the third [...] Oops, that should say "the first two lines return `true`, the third `false`" (the point here being that they return something, as opposed to the later three, which throw). On 9 December 2017 at 15:13, Aidan Woods wrote: > I prefer the inco

Re: [PHP-DEV] instanceof survives non-object variables, but crashes on non-object constants.

2017-12-09 Thread Aidan Woods
I prefer the inconsistency between `$x instanceof \stdClass` and `1 instanceof \stdClass`, than adding a warning (or throwing) to `$x instanceof \stdClass` when `$x = 1`. I think `1 instanceof \stdClass === false` would be reasonable. 1. PHP has no means of locking a variable to a type (i.e. the

Re: [PHP-DEV] Re: [RFC][VOTE] - list() reference assignment

2017-12-09 Thread Nikita Popov
On Wed, Feb 22, 2017 at 9:03 PM, David Walker wrote: > On Mon, Feb 6, 2017 at 10:54 AM David Walker wrote: > > > Hi all, > > > > Having seen no further discussion I'd like to open the RFC[1] for voting. > > Voting will be given just over 2 weeks ending Feb 22nd. RFC has > > implementation[2] an

Re: [PHP-DEV] instanceof survives non-object variables, but crashes on non-object constants.

2017-12-09 Thread Niklas Keller
> > That is fine for code that is broken in the first place. Similarly we added > a warning some years back about array to string conversions. > Code using instanceof on possible non-objects isn't broken. instanceof simply does an implicit is_object() check without needing an extra function call.

Re: [PHP-DEV] instanceof survives non-object variables, but crashes on non-object constants.

2017-12-09 Thread Marco Pivetta
The typical usage of `instanceof` is checking a `null|object` API that built an object of a (presumably known) type. Adding a crash there seems silly and overcomplicated. On 9 Dec 2017 07:57, "Andreas Hennings" wrote: > Why is the usage broken? It works :) > In practice, the current version of i