On 9 December 2017 at 16:19, Aidan Woods <aidantwo...@gmail.com> 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 interesting, I did not know that the right side is also inconsistent :) I think the default mental model of a programmer is that an operator or function only sees the value of an expression, not where this value is coming from. There is already an exception to this for by-reference parameters, which already feels weird e.g. for isset(null). The inconsistency for the right side of instanceof may be justified, I don't know. But definitely it is not good for shaping a clear mental model. The "1 instanceof \stdClass" is nonsensical of course, but not any more than if(true) or if (5 + 0 === 0) or unreachable code. I would say the main use case is for a programmer to find out how instanceof behaves on non-object values. In this case the experiment will give the wrong answer. It should be the IDE's job to tell the programmer if something is nonsensical. The language should only care if it follows the rules, and these should be as consistent as possible. So, imo: - we should let "1 instanceof \stdClass" return false without complaining. - possible inconsistencies on the right side of instanceof can be discussed separately. - extension of instanceof to other types, e.g. "1 instanceof int" can be discussed separately. I think the simple change would gradually improve consistency, without closing any doors on future changes.