Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109620 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 90368 invoked from network); 14 Apr 2020 14:21:23 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 14 Apr 2020 14:21:23 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A12591801FD for ; Tue, 14 Apr 2020 05:51:02 -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-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) (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 ; Tue, 14 Apr 2020 05:51:01 -0700 (PDT) Received: by mail-lj1-f182.google.com with SMTP id z26so12297174ljz.11 for ; Tue, 14 Apr 2020 05:51:01 -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=wbXzLFvSFu4EvYbtBp1sxb0lgWPB9MQw2GnYkku/AqM=; b=E5BSNhM3Aau8SoY6pN8v65bNUno5zAmfUAwGJdcA8xfTRS4Pn0knnGlD5pn4pkcyJ5 8qPFCHeWUmrfdcpR4xpP6wWtrQ0lHHLBkhOh2ARzLnyTOq1ob1LfXSZ+Q/Zw/LFEfajp 762kbD5QbCv2sxaOGkOorCxxYkJgKcZdPswKr6leDkUEDh5UL4cMJx1bdrc1DWIz/pgQ uAxZcNLlfKzT9qHA92ZqVe5fHXaOVVLXSN1yPd6Dyg2+m1zQ8MXIm5zvHhvtcCnYL7HM e2ZyWW9h7cNbPdd84vwJ8B3SZRUVMgvwLJvwPvvKTp4pDsLFbnW3AByOGwvrKO/aCo/0 Ftuw== 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=wbXzLFvSFu4EvYbtBp1sxb0lgWPB9MQw2GnYkku/AqM=; b=Ft6usGYOuejAohayDOAG3kqWzNET10SDxuf3H6e6KaumK6X1jVRPN+o8TjcjCr/NaH sJlk0RQ75Vx3M5UNGeNcd/23KU6rknnp+mjUdoEZu6fIj/UoSr95llVSXBMpXrDTIEIW NAyvO32bdcBd7CJSsphcygS9uFU8zJTr0kDFTCJc4tXJaxGOUevvAGMntELaWONo6NnG 9zXqc7SDcj0P+7MiV5bySpTJfwSBGyLlFk1KMilbERKOtVbADlf4StofVVjwUquB7qbv QB0Vxg2X5re7HyuHt6+p7QWnvcy30M2BDLlS2HqAAOcwUXqqLkOvPBORGTGmZD7CtRSY vlmQ== X-Gm-Message-State: AGi0PubKYH4JjV2Vm5G5X7SfWuS48hhPWm1mV/LwrZjKDqQxUiIbdXQJ 5hhPgSQS3+wusYOUnMC9VpTY2JbfxL0pOg9IWU0= X-Google-Smtp-Source: APiQypJCvxkETC2fseQWz1Dk0Jltd/ujFYhbNuVpaxwo43LZIsjDakGbhj0xWuFH9Q+kIAq6ct6F6+pOdY5SYkeUnTE= X-Received: by 2002:a2e:9605:: with SMTP id v5mr16625ljh.258.1586868658540; Tue, 14 Apr 2020 05:50:58 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 14 Apr 2020 14:50:41 +0200 Message-ID: To: Rowan Tommins Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000b2a88005a33fa655" Subject: Re: [PHP-DEV] [RFC] Stricter type-checks for arithmetic/bitwise operators From: nikita.ppv@gmail.com (Nikita Popov) --000000000000b2a88005a33fa655 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? > > 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. > I've now update the RFC to move the open question into future scope, as I agree that this is a larger topic that should be discussed separately. I plan to open voting on this RFC in a couple of days, if there are no further concerns. Nikita --000000000000b2a88005a33fa655--