Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101276 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 94448 invoked from network); 9 Dec 2017 06:46:52 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Dec 2017 06:46:52 -0000 Authentication-Results: pb1.pair.com smtp.mail=kalle.php@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=kalle.php@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.47 as permitted sender) X-PHP-List-Original-Sender: kalle.php@gmail.com X-Host-Fingerprint: 209.85.214.47 mail-it0-f47.google.com Received: from [209.85.214.47] ([209.85.214.47:46050] helo=mail-it0-f47.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 25/63-62356-BD68B2A5 for ; Sat, 09 Dec 2017 01:46:51 -0500 Received: by mail-it0-f47.google.com with SMTP id z6so8194090iti.4 for ; Fri, 08 Dec 2017 22:46:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=XdByPui468lmsI4UUx9oUhJev8ICb/fvsKCibblSVfM=; b=Qe2oXIEwAyE4/RQKVHvuBubpW2ctx4gbEEw1jHg+/WH7dGfNBpeMmjeMg9wraGADUL 1Rlgvcg1GuDqPqPJNcPpKPwZR0MvrwYTErNbSohAr1cwMuUPDDXv0Ck12zdONGbgcU7x r9MqyOO9q+5eet3O+JswGF33deWZHjtrmLXqSP81+SFWbI8mZt6mIGz5j6hfHm6Hd5pF cbBsOlLA3I+Mc/9DnCoWWyXfauuYTUc9AFwxkQ7taf8DF+bJZC5bXsmPH3KapjYA0Zxq V0sog5QEYmjDD9Zj7ac/8XTW61bPkb9a9ZH0OUUksqTN/a/qjpEZLELLo/b1MymKWnD1 lbSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=XdByPui468lmsI4UUx9oUhJev8ICb/fvsKCibblSVfM=; b=LWVtYbxh3i5gqs6zogE/3vtsVeBVIHmYeoWM38x6ZlnRXJ9dfJLN4Aa+G7nyazK03G 0Wq2FCKSlHUXhPVCNFoYFFZZFvH0DrprmwkheXeWAtvuEOjjYNATPp/WXD7VzB2J3yZ6 H5mLEmOYVK5uk+dBy9xXDSZ07JyFz7DWifYNMDDrlryhWCR1sb+et4DpNz8nv0IYMnfM 1OTYdR6mPbX8T3FeCUiuqo7RoksXSS0kgIcA1My51PA0MXSBFvsF9C8L2yUhZ4rdpCUd 5AGPK5iIxAFeJ0mxXg5os49DAbByVi6tmAg2Px9hr3Qk3rBchPDY43HhBL0AUOQ6YlM9 ATyg== X-Gm-Message-State: AKGB3mKUrq411thDNF56Da/n+WJtfQWMLGfgeHIQtDDqVMAj3c6pnFqx doL8XCmf9bYTo8+0Ts1XA6NwwWSrH19dV4H1QWw= X-Google-Smtp-Source: ACJfBovH5/jNYtPakdH/GKpWLpW5QDMnVGaCjbZ5KgdCakQ+T0QjAbBgQsKdP7CUtoOjXY61J+dqwZ+kU9PXD0tfX2A= X-Received: by 10.36.10.135 with SMTP id 129mr2516404itw.145.1512802008597; Fri, 08 Dec 2017 22:46:48 -0800 (PST) MIME-Version: 1.0 Sender: kalle.php@gmail.com Received: by 10.107.79.6 with HTTP; Fri, 8 Dec 2017 22:46:48 -0800 (PST) Received: by 10.107.79.6 with HTTP; Fri, 8 Dec 2017 22:46:48 -0800 (PST) In-Reply-To: References: Date: Sat, 9 Dec 2017 07:46:48 +0100 X-Google-Sender-Auth: DzXnGUjleU_8N0lDwAIwfRVZEKA Message-ID: To: Andreas Hennings Cc: Internals Content-Type: multipart/alternative; boundary="001a1144b27a568e28055fe2aa02" Subject: Re: [PHP-DEV] instanceof survives non-object variables, but crashes on non-object constants. From: kalle@php.net (Kalle Sommer Nielsen) --001a1144b27a568e28055fe2aa02 Content-Type: text/plain; charset="UTF-8" Hi 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. If your code is like the example, it should be updated and warned about as you are doing something illogical by first checking the type and or value of the operand you are passing to instanceof after. The impact should be minimal as is, so persevering bc for broken usage is a poor argument imo On 9 Dec 2017 07.38, "Andreas Hennings" wrote: > Adding a warning to something that used to be ok would break existing code. > I remember a number of cases where I used instanceof on possibly > non-objects. > > if ($x instanceof C) { > return $x; > } > elseif ($x === NULL) { > ... > } > > All such code would then produce warnings. > > > On 9 December 2017 at 07:35, Kalle Sommer Nielsen wrote: > >> Hi >> >> We should just add a warning to the first example, it seems like an >> oversight that it was left silent >> >> On 9 Dec 2017 07.29 <20%2017%2007%2029>, "Andreas Hennings" < >> andreas@dqxtech.net> 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 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. >>> >>> So it seems the first would the option we should take. >>> This is also what hhvm does, according to https://3v4l.org/IdSBu. >>> >> > --001a1144b27a568e28055fe2aa02--