Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109513 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 98899 invoked from network); 2 Apr 2020 14:44:17 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 2 Apr 2020 14:44:17 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9843D1804B8 for ; Thu, 2 Apr 2020 06:10:58 -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_H3,RCVD_IN_MSPIKE_WL,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-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 ; Thu, 2 Apr 2020 06:10:58 -0700 (PDT) Received: by mail-pl1-f181.google.com with SMTP id e1so1308904plt.9 for ; Thu, 02 Apr 2020 06:10:57 -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; bh=pA8+ZwVvDlnLJY68DrW6AbGuVTJHQ0rpgTAW6DHDCF0=; b=fXbAyv0CVafcn8VyK0yHFn7zFKDWVu1WeNOSp8RJR20JKSxO9LdMxM13xXUzFVA+D8 KJVay5WWTSbm+bNLWfzSqwiQzZJS4T750kW+KIk5X6h6x5hncwWJu0EPnxCD6oCpo44q j+ZsH1nrhmCDm93F4b0l/Kr85wdeHLoZLN1nMnq63kSWtT6hOelwqwsCtsYqbh/PElDI P2y1vTCS0Q1udRn3O3Fqo7t01roVjBkjvCjRMkuceqtxhZPqj7Qj3daVprsoARWurn1r w/LFazl1fGhV+cD/mmHCSgZbxi1XcQ0gFnh+REP9cTN/1NRLCE3eQ/S6MCjNIObb4qJ9 6L5Q== 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; bh=pA8+ZwVvDlnLJY68DrW6AbGuVTJHQ0rpgTAW6DHDCF0=; b=DjYe/okqxazwAF3JplEw1foW5Li5Zoq3Ciw7GuxaRN8YzCMPOBlWDI6/OHxMtcvrVH vaEZ1Vdss1zI5YKq1MQOxBYB2fnFa6UJaJmuiteFOooNKOMqjSNbJy2zyAVaFVMUlxTa ZV/qH9VG494CVfpMmM6ttmGEUJfJXI61zlC4P4PFaZPNRLZIrILOHvTVxUZE53SIJ/wb dAgF6i/I+B+3LKUvXsNHqKjfc6m0T/uHPUzGtlFLsv5xviWgbbQrFEEPPn328FYcIXAY CgDGeUX/oHQJDTY6kNk7l9E94pqpNKR/HokPELO1c/31cD73uD773DwVBUATbjklPYqm 3zew== X-Gm-Message-State: AGi0PubN1LYJ9gMcXBUC7x5qLtjWnXeby048rsOkBczIq7HRKoEctCJJ UWKWU+/GIkqK451G9cf+67szYjJ5zFJRnBskIGH/I1Ly X-Google-Smtp-Source: APiQypLse2kC87Pkfh5UeeXQhKQeYgQve/Y4EPrvSbsmnezHowmePzYXlkWBE+WnI+BTT2bcOacA+vTAs3yGFfLf4vU= X-Received: by 2002:a17:90a:bb88:: with SMTP id v8mr3834181pjr.54.1585833056763; Thu, 02 Apr 2020 06:10:56 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 2 Apr 2020 14:10:43 +0100 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="00000000000005845c05a24e88e2" Subject: Re: [PHP-DEV] [RFC] Stricter type-checks for arithmetic/bitwise operators From: rowan.collins@gmail.com (Rowan Tommins) --00000000000005845c05a24e88e2 Content-Type: text/plain; charset="UTF-8" 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. Regards, -- Rowan Tommins [IMSoP] --00000000000005845c05a24e88e2--