Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101277 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 95995 invoked from network); 9 Dec 2017 06:57:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Dec 2017 06:57:23 -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.53 cause and error) X-PHP-List-Original-Sender: andreas@dqxtech.net X-Host-Fingerprint: 209.85.215.53 mail-lf0-f53.google.com Received: from [209.85.215.53] ([209.85.215.53:37943] helo=mail-lf0-f53.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B7/B3-62356-0598B2A5 for ; Sat, 09 Dec 2017 01:57:22 -0500 Received: by mail-lf0-f53.google.com with SMTP id e137so14005049lfg.5 for ; Fri, 08 Dec 2017 22:57:20 -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=KCXfecTjLpWAuISAAmjE1eZ3u0E1uQ7d15tVGB+7HrU=; b=atotJyQylo40a26pWyFxQrXattsj/TVd+RfTA6ZVazNYEj6qO4umgCf1HV+jJ7syPl aXj93Sre+Cp3CYBaGFpDRR2tkN0w3UUBhrWHu5j+40u11VayTjcQ/kDmO8yBsVVTfRWZ 1IG8UIc1y3PlzG+lWm8hkqD/mqLQGmnHtXEV3mqVCKflkTzduiNeK3TPA5CYBs8Lo7Nz tpjig6Y2qPz00JHn4zLPLTA7qv9rqlBrs6pnAAvhot1rq7qZ074py2s2Ot9JrLF9ZFtE Cx2gN87TTvrWSVoIm8Q10B0I2GLPnEq9v0dNZ7uf5nYcf0mILoHt2fHafigntJbMmIfZ fd0Q== 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=KCXfecTjLpWAuISAAmjE1eZ3u0E1uQ7d15tVGB+7HrU=; b=dSzZ7kNeqXYF8NPllw1ueJCA43F28t0EJzuoml7+tNjAryEHjYjj2kyoPsLv449U0g nm7kVYRdCA/m22QlwIX2y7Js10NlETMf+mFeChI9no/958HlHPhRPTDglQ06nFkPlpYD HsvskGGLyNyBtIpZJDWJ/MT3EiNeiASHQSQ65tcM4NDt+oe7mwTgmhZKDzu4m+zIBoup nN90KxPwJrTGeGRew+lPrVYeiLQGy9MBDsVAB/TyE03bTJpJS5t2tu4R60O4YA7Zsv8I NJfY00UudwAV/HhaVW5JbcIlxqVgtS+43gy+Cnnt7hydehoy8tge4R4jzHZLWzN80xpI ildg== X-Gm-Message-State: AJaThX4MBGaYZo5Mv5xL76jFUUukTVpRIRvI0Xw0iN9G7RpxH4T8F48N PLI9ATJ6fqfMlI6uZtz0JtB3bjM8 X-Google-Smtp-Source: AGs4zMZVV9GeeJfp04zvNti0LRlp45ZTcIAWwGoROmo4JPoSh3w4oP5hnG0Mkn2cgVdEPvzRspOlcA== X-Received: by 10.46.69.67 with SMTP id s64mr17687160lja.94.1512802637461; Fri, 08 Dec 2017 22:57:17 -0800 (PST) Received: from mail-lf0-f53.google.com (mail-lf0-f53.google.com. [209.85.215.53]) by smtp.googlemail.com with ESMTPSA id u23sm1791285lje.79.2017.12.08.22.57.16 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Dec 2017 22:57:16 -0800 (PST) Received: by mail-lf0-f53.google.com with SMTP id e137so14005009lfg.5 for ; Fri, 08 Dec 2017 22:57:16 -0800 (PST) X-Received: by 10.46.3.10 with SMTP id 10mr5974316ljd.41.1512802635810; Fri, 08 Dec 2017 22:57:15 -0800 (PST) MIME-Version: 1.0 Received: by 10.25.170.16 with HTTP; Fri, 8 Dec 2017 22:56:55 -0800 (PST) In-Reply-To: References: Date: Sat, 9 Dec 2017 07:56:55 +0100 X-Gmail-Original-Message-ID: Message-ID: To: Kalle Sommer Nielsen Cc: Internals Content-Type: multipart/alternative; boundary="089e08274e44b90edc055fe2cf64" Subject: Re: [PHP-DEV] instanceof survives non-object variables, but crashes on non-object constants. From: andreas@dqxtech.net (Andreas Hennings) --089e08274e44b90edc055fe2cf64 Content-Type: text/plain; charset="UTF-8" Why is the usage broken? It works :) In practice, the current version of instanceof has an is_object() built-in. This is what people could assume from trying. Of course I don't know how it is implemented internally. Maybe a kitten dies every time I use instanceof on non-object variables? If we need an additional is_object() it can make some code more expensive.. On 9 December 2017 at 07:46, Kalle Sommer Nielsen wrote: > 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. >>>> >>> >> --089e08274e44b90edc055fe2cf64--