Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113104 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 87439 invoked from network); 6 Feb 2021 20:45:03 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 Feb 2021 20:45:03 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id F19341804E3 for ; Sat, 6 Feb 2021 12:29:21 -0800 (PST) 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-Virus: No X-Envelope-From: Received: from mail-oi1-f171.google.com (mail-oi1-f171.google.com [209.85.167.171]) (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 ; Sat, 6 Feb 2021 12:29:20 -0800 (PST) Received: by mail-oi1-f171.google.com with SMTP id m7so11411448oiw.12 for ; Sat, 06 Feb 2021 12:29:20 -0800 (PST) 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=1Tgp36yZotrtWwsAPMO7EHReoXbzUoQkOEEz5ob8inM=; b=hWnaBWsf9dRBZP0Z0FQrxd4w7KmBkeox/7ioJpjON3p4xUsXZ4qSxWpj9qICnGEoOm hU2FhRO+PCSSmGVyVEUkux1Fh3zyoYCJOebkcRD3ZELp0bNkQkmwfkg693bNTcesaVXt Q1ChVqspab+Z8w+iyeWoklUkM//T8fbzMFBLmfvL9GFJIhBmeZ5lA0lXqVdnbU2Yhc8V +I2GEekRGONJAhNSf9ZMYBfZQVlFtidGemJWpCdT+gYZso2gmQZieggdxsQYE1QcxBtF IpJpLbbm9B6Ex0wslveIMTcRfXvCVfueaykYiiUaO/dSxsClHKYHgGxbN9wldkJMXLbl zyzA== 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=1Tgp36yZotrtWwsAPMO7EHReoXbzUoQkOEEz5ob8inM=; b=iKCx3s+5jFllSID3PCXBpZTZ5Y7swdOg8zg+bVPN38b6WlIqt0YOUk7lhi4lyvDgUH /7DnyEnHI/vq9E8P1FrVqhYxm0dMv0v9dPIttKuITBhrOOhKfa/GjKTEpACz1cVnH6Zf whjKgpWeT6/3cr3kwM+BmBohKIss6780qenJqc7m8222oLnsSxW7JgH6tqSKMySAtvrG H1eXTTvoiAogpBYuQ8dOs1J96kU4vLEILwA2UqWe5Hpfs5TluVtjwALh4jBSoEPxB0CE HlhR4brn3v8sIOe8Ve4BqIA0cjumve7JPuHLiLyXW1ldBCapE7sFDZBcpz5ifLKEWX7G IQxQ== X-Gm-Message-State: AOAM530w9dPMuCInAxRum+nGVdiFLfZC9T6CzSHxdc72NSlrklJFuKFU J1azNZrPp6K31QqXhNigkdpISkshCUomJPYLhAk= X-Google-Smtp-Source: ABdhPJw88Tp5uPs/d8l8XSejoWLpK8iRSAZnclsM+SThImUKnFqTWrvcX3irYgB2uu9C4YatjRZB4lKvXyAexqpL9lk= X-Received: by 2002:aca:c7c8:: with SMTP id x191mr5107174oif.152.1612643360069; Sat, 06 Feb 2021 12:29:20 -0800 (PST) MIME-Version: 1.0 References: <248543D8-4266-4495-9FC4-762A63625A93@cschneid.com> <0d04114d-d90a-913d-627e-16006ec655ef@gmail.com> In-Reply-To: <0d04114d-d90a-913d-627e-16006ec655ef@gmail.com> Date: Sat, 6 Feb 2021 20:29:09 +0000 Message-ID: To: Rowan Tommins Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000a05e3405bab0ca42" Subject: Re: [PHP-DEV] [RFC] Warning for implicit float to int conversions From: davidgebler@gmail.com (David Gebler) --000000000000a05e3405bab0ca42 Content-Type: text/plain; charset="UTF-8" This is all a bit moot anyway, the RFC proposal is for warnings or notices on implicit casts only. I'm not a voting member for RFCs so my opinion is mere food for thought, nonetheless my two cents is that: a) The proposal relies on a premise that an implicit cast of (non-zero fractional) float to int is inherently ambiguous or a mistake. I disagree with this as outlined in my previous messages; namely my objection is truncating a float on cast to int is the widely established normal behaviour in numerous programming languages. There should not be a penalty in the form of an error just for doing such a conversion implicitly, in accordance with how PHP's type coercion works by design. b) String offsets, where a warning occurs already, is something of a special case; this warning was added I believe (5.4?) because malformed string offset was a known common error in the community. It's not even entirely consistent; $foo["2"] is fine, $foo[2.5] is a warning with offset [2], $foo["2x"] is a warning with offset [2] and $foo["2.5"] is a TypeError. c) It's a substantial BC breaking change likely to affect a lot of existing code, even though that code works as intended. d) If it is implemented at all, it should not be an error level as high as a warning. -Dave On Sat, Feb 6, 2021 at 7:32 PM Rowan Tommins wrote: > On 06/02/2021 14:47, Christian Schneider wrote: > > I'm sure there is a lot of code which takes user input and uses (int) > casts to ensure they are dealing with integers. > > There is also intval() as an alternative but my guess would be that real > world code uses 50% (int) and 50% intval() to do this. > > > My thoughts exactly. Code along these lines is common and, in my > opinion, perfectly reasonable: > > $id = (int)$_GET['id']; > if ( $id !== 0 ) { > // throw an exception, return false, look up a default, etc, as > the application's design requires > } > // proceed knowing that $id is a non-zero integer > > > I would however welcome a new function or syntax that either performs a > "strict cast" (producing an error if the cast is lossy in any way) or > checks in advance if a cast *would be* lossy. > > Regards, > > -- > Rowan Tommins > [IMSoP] > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > > --000000000000a05e3405bab0ca42--