Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101286 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 40439 invoked from network); 9 Dec 2017 23:40:17 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Dec 2017 23:40:17 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.169 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.223.169 mail-io0-f169.google.com Received: from [209.85.223.169] ([209.85.223.169:40709] helo=mail-io0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F9/98-62356-0647C2A5 for ; Sat, 09 Dec 2017 18:40:16 -0500 Received: by mail-io0-f169.google.com with SMTP id v186so6032832iod.7 for ; Sat, 09 Dec 2017 15:40:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=HMtkRID1mty8YzSQScgbVxL0v+zN2UqhBPFPCXTzHG4=; b=S30kYA2wavmKvTd8JfajRus7xh5o0f2MSt53F4FyPuqRt9hvEsDjuvhqCNe6xexvMe 23j7JxsR5I6uzrN4oI8ejo9/5ivoQzo7Z85pXtn9Q6wrWmdLupQyqtaU4uHuQ2uU5QIA H3fWntEua73dWEsmTbJKjaec8xfBNFHOpf4P2ARq5/QDs8O4Z/cWRP8CXDnKCRvt47CX AydHKBZjKN2GGNhvCYO+EmAMTVrNUglMG59vPaoLU7Lx/3EoiQ3OEuLt9ALK4iu30uvV hPqI6HukRHfsYSReWbkx46TZCg4d/m+BnSIAmqNnUCTr7mHcHYBEWSy6tHJwJaK53w56 V3fw== 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=HMtkRID1mty8YzSQScgbVxL0v+zN2UqhBPFPCXTzHG4=; b=Ws3C1i1mN3KiaeRjh35FMURG5MvUtxJyXJ4uSAmq0X/FdDcDFqwRZE9TH5VbYBYvq8 R3DIpcUhkROIWkry8LWe8gz8KY9ygOKJ8JWHuMhDObKYQQYfpld4HJR51xwh6HTuXGMc +z0TdIdZQ3yCPntHpgwIcOsd2ao9+4DTtV6kbXVKnlLIPf+iFVmtl3M9MPTnveeYos90 Ts37ER9QpUkypa7n0xYx6bmUKurvjXmf4lvx3KxmABs0xu4w4GNtsp1p+ReRAsramYAG pIIN9ugQ95RWGi0xYc27tosRmeBkwO39HSCrBidNM8CVNFph4PFlAlXua+F5kSnYg+NU rDqg== X-Gm-Message-State: AKGB3mI75IZLsV3zZsFah6pZRdB/zRCfvau/87Y3Bbxzxmloqq/Nz9zc mv+M1/pIFduMxtoxng7Gmqo0kPmaJ69cBiScbgU= X-Google-Smtp-Source: AGs4zMYOhBqInnuMyCa/4qgBZWKtju9igeNYncJS+4CJ76c1KZEBPdkSxOUKt2p/XyfP0Rxy8Hil40UmSp34CpE8RDo= X-Received: by 10.107.169.152 with SMTP id f24mr12837794ioj.219.1512862813959; Sat, 09 Dec 2017 15:40:13 -0800 (PST) MIME-Version: 1.0 Received: by 10.107.138.93 with HTTP; Sat, 9 Dec 2017 15:40:13 -0800 (PST) In-Reply-To: <50e2ef67-7f9e-3910-988d-684cf9c57be3@gmail.com> References: <50e2ef67-7f9e-3910-988d-684cf9c57be3@gmail.com> Date: Sun, 10 Dec 2017 00:40:13 +0100 Message-ID: To: Stanislav Malyshev Cc: Andreas Hennings , PHP internals Content-Type: multipart/alternative; boundary="001a114277fc9ec149055ff0d22d" Subject: Re: [PHP-DEV] instanceof survives non-object variables, but crashes on non-object constants. From: nikita.ppv@gmail.com (Nikita Popov) --001a114277fc9ec149055ff0d22d Content-Type: text/plain; charset="UTF-8" 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 $x instanceof \stdClass crash, if $x is not an object. -> BC break. > > Neither of those "crashes", one of them returns fatal error, which is a > valid option for code that is obviously broken. It would also be a valid > option to return false, but since it is a valid outcome either way, I > don't think changing anything is necessary. It does not make any real > code easier to write (I can't see any legit reason to test numerics for > being instance of anything) and does not improve anything but abstract > "consistency", which in this case is not useful for anything. > The main issue seems to be that if people are not sure whether they have to do an is_object() check before using instanceof, they just quickly test it using "42 instanceof A" and then draw the entirely wrong conclusion from the generated error. I've certainly seen this play out more than once. Which is why I'd be in favor of changing instanceof to returning false in this case. Nikita --001a114277fc9ec149055ff0d22d--