Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113078 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 57965 invoked from network); 4 Feb 2021 18:11:18 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 4 Feb 2021 18:11:18 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 481021804E2 for ; Thu, 4 Feb 2021 09:55:04 -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=-0.2 required=5.0 tests=BAYES_20,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-Virus: No X-Envelope-From: Received: from mail-ot1-f41.google.com (mail-ot1-f41.google.com [209.85.210.41]) (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, 4 Feb 2021 09:55:03 -0800 (PST) Received: by mail-ot1-f41.google.com with SMTP id k10so1893109otl.2 for ; Thu, 04 Feb 2021 09:55:03 -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=tRCPhr1BzFIT9agdRFcxojZ3g5oZ5UOFvgIehcknFA0=; b=DjXEJvgLCwL7QZkrerNKBvICLwAGMxv9rAzwXEGlEkTswU72kI+o22eiZNBEw1mdaB Cbz2aNzG/raay9gzJjD+ulbtOvOCFh4D7oKen85uk6PmOS4pudtbimV+CHVNvwt7JL1m XJ83SK06jhriw2IVjkx/xO2LHmpJEGXwJosdVFhgPUBUwwr3Pu4op6sMNZZYPqf5pZgE X5sOhOoH9kqb2O0CoOl9GMBNrYa9f/+39b83xNvoDaybqSpWB0eZRgG5CyIFdOcJNpsA /Jr88l8tyUzZezp6SU7NGIXYAS9egnBPOAdlaTUhLd9enrlRpILWVynRfGpvmuAS8C5c V24g== 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=tRCPhr1BzFIT9agdRFcxojZ3g5oZ5UOFvgIehcknFA0=; b=S/Fbl9cQ1/whWafe16xVBwlnXv6GpTWk1VfSsLhr5+GDzSceeGVWwD2c08vDqrXM5P FL88IrncAxS7EIQZa0OmvwEFjRkuSMZrl11q2l3UWdVC8LE+0ISlITO6bvm36CdQrpbw fEs0tD/2W/7vGAZhgKQpBClQtFMPcsOrY3Y68bhtLCIQ7GKb+ZgeQHw+/qT7yZnAt51g Fj7RNT/vYmTqm+SCbDAEX4dkhiBorcCBteT0CnT6yzgNqW5TWfXLt7ysXL+xnyJIdt/V XRnQ9fQ1mXsPEN7FH0Z4R5ZStROtRSbpHP4QrP5lJjCizE4798//5KO4G7IzrEyBIPup kSBw== X-Gm-Message-State: AOAM531Y3K0fpiAzwm1Pd53sdEcdUQv8776eSg/TZS/ea8/V6XsZlfhj /drUcEV1IMogK30N07v0nbJVKwjJKM86rCyH4M4= X-Google-Smtp-Source: ABdhPJyiaZVKT8GvXwN4v7GJf0gT9vgXmUY+f1CMl8KIAvNMsnsqZBGq8rlWG05GZ4w2CJa0lHhxesae+aYbmU7IVIA= X-Received: by 2002:a9d:6d85:: with SMTP id x5mr404457otp.135.1612461303060; Thu, 04 Feb 2021 09:55:03 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 4 Feb 2021 18:54:52 +0100 Message-ID: To: "G. P. B." Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000002edc8c05ba8667da" Subject: Re: [PHP-DEV] [RFC] Warning for implicit float to int conversions From: benjamin.morel@gmail.com (Benjamin Morel) --0000000000002edc8c05ba8667da Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, 4 Feb 2021 at 17:05, G. P. B. wrote: > Greetings internal, > > I'm proposing a new RFC which would warn when an implicit conversion > from float to int occurs. > > The draft is currently located on GitHub: > https://github.com/Girgias/float-int-warning/ > for ease of commenting/providing changes to it. > > The official discussion phase wouldn't start before I convert it to docwi= ki > and > post it on the wiki, something I'm planning to do next week. > > Any feedback is appreciated. > > Best regards, > > George P. Banyard > Hi George, Thank you for this proposal, I'm all for it, though I'd go one step further, and actually issue a warning during explicit casting as well: (int) 3.5; // E_WARNING (int) round(3.5); // OK In my experience, it's better to be explicit about your intent, so forcing the user to round() before casting when the float has a fractional part is OK to me. This would help prevent weird silent conversions such as when you cast to (int) from user input: $age =3D $_GET['age']; // '25.75' $x =3D (int) $foo; // I'd expect a warning, not a silent conversion to 25 =E2=80=94 Benjamin --0000000000002edc8c05ba8667da--