Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109519 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 25237 invoked from network); 3 Apr 2020 09:37:02 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Apr 2020 09:37:02 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BC7DF1804D3 for ; Fri, 3 Apr 2020 01:03:54 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 3 Apr 2020 01:03:54 -0700 (PDT) Received: by mail-lj1-f174.google.com with SMTP id g27so5963018ljn.10 for ; Fri, 03 Apr 2020 01:03:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=a0B6A7tpP04nD8aU/NmwGzv3mUa+hE7GoJGoTcPqZkQ=; b=JMCn4As6dW5DHm9tg3DlBvkOG/WA2aGrawRUZWyB7BWVxIIf1Q7Y84my7DA14FMMQ3 tfcCimyM0ns2904OnUY/mQWVcPjCKfrft8pEHMdHW5RyFZ4JFC8c9BD5lajxqRMze7iN YkJHmYMpcaK3qFmo3G2Z93wWxCLibVJvGo6shd+ITT2uD9tDGD4UElyZWb0qakf1yRlU yLlOatkP860kbGR1Ya/Pj7OUjfJvx/dAy+wBURrRVh5bOwpdSUpBqaQG3zIoXA9EPuBv 6cr8DAnS6oVSq2B48x268N60cHIua/iYKE6HYvMPQ1E5pkxlskokesKPODkffddCIccg Cdgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=a0B6A7tpP04nD8aU/NmwGzv3mUa+hE7GoJGoTcPqZkQ=; b=bk7+0NZ78eykPAr5qLLQtXGyqL3tFLwYyMLiVlyTIyfsix8dH6tO6ck/p3u+Ed/Zni NRU0bYPkaa3BOUiKfnu8RObkY4zZ93Vm1y/JrSkcLC7H8ijCbX7RGxzQWCF7GgZ5ua9F fG9krWQrXRqOupdUlBJB+xFM/nrbKwSGX51ANnR7MeKlLw0NdkctMhpEE1bV//rk/Lhf q1Y/3jRZE9BnOzayqsHoaX9dVGTHg/+f9kP9YVRS/5hsY9iYlzYZq7LtYFZ+veANW5gu Pl1H7CaCnzKUPA1Mo3UqY3uGW3/yYKvA+mgpRbi6GDlgdt+whfn4i9UJRdqHlE+0FLzZ iMpQ== X-Gm-Message-State: AGi0PubehfvTTKfcHnV0RzHAOgnNdWVMR1bQckO1maC0JCnGIUO1Fuln eeTSuSnnNQsYHBpKmyvz2jvasBvkc88103vx2ac= X-Google-Smtp-Source: APiQypIeIysEV5eULAv3DMxEIcoNvK3ejxWJBcw1K278KEuJnM9yDXDleTIbbqRjvcV5CR+Zr0qJ4sgMUAz3hnn16Og= X-Received: by 2002:a2e:7205:: with SMTP id n5mr4126851ljc.192.1585901030269; Fri, 03 Apr 2020 01:03:50 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 3 Apr 2020 10:03:34 +0200 Message-ID: To: Rowan Tommins Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000008ee73d05a25e5b92" Subject: Re: [PHP-DEV] [RFC] Stricter type-checks for arithmetic/bitwise operators From: nikita.ppv@gmail.com (Nikita Popov) --0000000000008ee73d05a25e5b92 Content-Type: text/plain; charset="UTF-8" On Thu, Apr 2, 2020 at 3:11 PM Rowan Tommins wrote: > Hi Nikita, > > On Thu, 2 Apr 2020 at 09:14, Nikita Popov wrote: > > > I would like to propose making the use of arithmetic/bitwise operators on > > arrays, resources and (non-overloaded) objects a TypeError exception: > > > > https://wiki.php.net/rfc/arithmetic_operator_type_checks > > > > > Thanks for writing this up; one of the conclusions when revising my inc/dec > RFC was that this should be proposed, but I've not had the energy to follow > through. > > Discovering that objects become int(1) was a big WTF for me. I'd happily > see that throw an error even under an explicit cast - "(string)new class{}" > is currently an Error, but "(int)new class{}" and "(float)new class{}" are > only a Notice.Would it be possible to throw an Error in this case without > fixing the comparison operator quirk you noted in rfc/engine_warnings? > In preparation for this change, I've decoupled the error reporting from the cast logic, so it is now possible to make just the cast throw, without influencing comparison. However, there might be exception safety concerns, along the same lines as https://wiki.php.net/rfc/tostring_exceptions for the string cast case. Nikita > I initially thought resources made sense as they are, but like you I > concluded that the only real use is to get the ID itself, so explicit casts > are enough. There's a possibility that someone used to JS might write > $resource+0 instead of (int)$resource out of habit, but it doesn't seem > particularly likely, and is easy to fix. get_resource_id() is a good idea, > too; for similar reasons, I've often wished objects with __toString() > aliased it to a more specific method, rather than it being the only way to > get a certain representation. > > While the behaviour of other types such as strings would be nice to > revisit, I think it's worth keeping this RFC to arrays, objects, and > resources, because other cases have a lot more to consider in terms of > detail and backward compatibility impact. > > Regards, > -- > Rowan Tommins > [IMSoP] > --0000000000008ee73d05a25e5b92--