Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101284 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 31575 invoked from network); 9 Dec 2017 20:14:53 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Dec 2017 20:14:53 -0000 Authentication-Results: pb1.pair.com smtp.mail=andreas@dqxtech.net; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=andreas@dqxtech.net; sender-id=unknown Received-SPF: error (pb1.pair.com: domain dqxtech.net from 209.85.215.48 cause and error) X-PHP-List-Original-Sender: andreas@dqxtech.net X-Host-Fingerprint: 209.85.215.48 mail-lf0-f48.google.com Received: from [209.85.215.48] ([209.85.215.48:41415] helo=mail-lf0-f48.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6D/B7-62356-C344C2A5 for ; Sat, 09 Dec 2017 15:14:53 -0500 Received: by mail-lf0-f48.google.com with SMTP id f18so15176749lfg.8 for ; Sat, 09 Dec 2017 12:14:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dqxtech-net.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=PvUtY8amizGIbaGTFV2+QnQgWi4yq4kP7rD5fLao0UQ=; b=dDf6wmDEzj1NZ2e0vP4xpTX/RmL/my2oCyxXoB7UU4twrFKcrYdQp7UCGN9iz1Rxgy wqtTRFlZKes/GaB9OlUC63QFY1FoOne20FUuaQpInB/xBl0oufASS/MZxenk5PFpLa5S LFJA3CaZZQBSZ7VG8cv4KBFArNIlupLEJBjl3wkm8vH8Qv2eID6W880fGOFY+X1phUC4 7mddsC2gUPf6OOWMr5xono9gWwif6lp1+yN2j/0P0lS3+DL/tMkerNm9KD3GFkDFQ/n4 /e+w1CB6zrJ5FiyjDQw1YVUuOyDrVwtdIVafcfdfoUm6InU+J+J6QgPyr89ZsZayg0nD RWGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=PvUtY8amizGIbaGTFV2+QnQgWi4yq4kP7rD5fLao0UQ=; b=iRW93jzbWH6IP9z21PTJgl0pXqF67g3/s+jjAMwOhZNJyrdvk2Y/38eJiwDTjKPb/R 23DaStpQK5MdYh3VFnUjqCZb6Gq44ucqHlfVmmvqyeR/c4AWiQKs83ZERBNLYFi3vuJp nCgvtdd/OiBtiwjlbIXPeCjwejjRf/x5ZWyYUKCZ6fXYL7GmkZKEPHGBn4PHvu1dSrqB e4la98sicwYlrKv7U0PwbVugGmc48qAN2pGDWGLZjo0vUu+UkMpgCUwshCrko2RSjEBi T1d7jdO9YmbmqQHw1V9JlBtOAB5AM1JOB9HnvhUJDaEDEOCLmW3l9L+13d3XzYzSaJvK 4Xcw== X-Gm-Message-State: AJaThX7J2NsWD0pvUMq+gRxnw7VVPr6xVt8gVnZon3r7sWn4Td8Xuzoy /w0cNJ9hdjl/+P4pdeaOtKvhgc9k X-Google-Smtp-Source: AGs4zMY5kVrKIKHSVox7x8TLtJbW2Tlu4vKJSyu76jFrgiT+iqF3xPiL32AWp1H2JRKocv/MsEzBUg== X-Received: by 10.25.229.148 with SMTP id i20mr14833214lfk.114.1512850489364; Sat, 09 Dec 2017 12:14:49 -0800 (PST) Received: from mail-lf0-f48.google.com (mail-lf0-f48.google.com. [209.85.215.48]) by smtp.googlemail.com with ESMTPSA id r7sm2059620lja.32.2017.12.09.12.14.47 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 09 Dec 2017 12:14:47 -0800 (PST) Received: by mail-lf0-f48.google.com with SMTP id 74so15213552lfs.0 for ; Sat, 09 Dec 2017 12:14:47 -0800 (PST) X-Received: by 10.46.3.10 with SMTP id 10mr6669342ljd.41.1512850486945; Sat, 09 Dec 2017 12:14:46 -0800 (PST) MIME-Version: 1.0 Received: by 10.25.170.16 with HTTP; Sat, 9 Dec 2017 12:14:26 -0800 (PST) In-Reply-To: References: Date: Sat, 9 Dec 2017 21:14:26 +0100 X-Gmail-Original-Message-ID: Message-ID: To: Aidan Woods Cc: Kalle Sommer Nielsen , PHP internals Content-Type: multipart/alternative; boundary="089e08274e44df6ef5055fedf396" Subject: Re: [PHP-DEV] instanceof survives non-object variables, but crashes on non-object constants. From: andreas@dqxtech.net (Andreas Hennings) --089e08274e44df6ef5055fedf396 Content-Type: text/plain; charset="UTF-8" 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 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. --089e08274e44df6ef5055fedf396--