Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113097 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 93496 invoked from network); 6 Feb 2021 00:33:36 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 Feb 2021 00:33:36 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id AAE95180089 for ; Fri, 5 Feb 2021 16:17:41 -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_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-f42.google.com (mail-ot1-f42.google.com [209.85.210.42]) (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, 5 Feb 2021 16:17:41 -0800 (PST) Received: by mail-ot1-f42.google.com with SMTP id i20so8641419otl.7 for ; Fri, 05 Feb 2021 16:17:41 -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=nWO3RbJPnd52P7llvPZV3jBalDuzG+K6x7P0G8gUsS8=; b=IIGLyQ/oiD1wxal+o4EtyNPV8rlx1d1Rm9rFk7VWTLXaclJljkmGtMbpHC1ixktC7p MdzuaeD9L8o1vFd34c84yjfgpxU0e1+CxYS5UyaWuR7TL4ZZq3JlPOc7flbt1X1iul7+ rcOyKjoaqK76wgweplkuuioBYEHOnSNmT4DtlnlznsuLuG2O+yCzWArDEN4PXTqUmf+Z w75HstRn6AUc8+IwSrUp0gt9W/TGzXB7S+72z21l3m1Iju8P3USNtm5hETjMAJQd9Ata 2uAZqXf8AMmOxHoR4kL1H7GfQlxxteo+HqOPeM5xYb4MHaWYWcid1CR11kyIReDv/tci ikIg== 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=nWO3RbJPnd52P7llvPZV3jBalDuzG+K6x7P0G8gUsS8=; b=gIR7Q4E8bB4ttdyuELeaiu0/kIItg6YVxRVWJWWm557qyuJ90MH86JCcZaXsA4pvWy NcbvglH8RT0742Qzs0kodd+PhvVpnLLfqG9qCbig+8NVDFzPkluyCJh+4tCPA6ji2B0+ cvnh1Iuqiiwak9Kk4/9DwZiimrqP6AJQbLdB/DVu5Y7tJyJ6i6K18Pa/2RMUYiwzrfo7 xLhznhmEXO/rV4+nW+lY/DtAOkSy6JKXi607WITXBgg1aTKVPjdgNByHl85gothHMPgT 25WBeyfVUvBntRuAgkxm/tF55tE+F0h589R8kFXHX0m+HUAhr9QoinfG180jjleQC3Q6 dSFg== X-Gm-Message-State: AOAM533wzXsf0pRyvzGTpnwJ+YTNQEOt9wnc4QCSNbdiQtrAd3EuYRcw Lupm7XZkGSr3f/OJgFlktYPjmUXzpRrZTOb7XBE= X-Google-Smtp-Source: ABdhPJydLgPCGQhKDdjfzqCoQc3AF4MvEULhn/pf3odQsnlyZsX9OAdWx3U+XjsUCLwd4JJw/wxXo8tBkUFaQJdz2AQ= X-Received: by 2002:a05:6830:18c4:: with SMTP id v4mr5057820ote.358.1612570660494; Fri, 05 Feb 2021 16:17:40 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 6 Feb 2021 01:17:29 +0100 Message-ID: To: David Gebler Cc: AllenJB , "G. P. B." , PHP internals Content-Type: multipart/alternative; boundary="00000000000064e19d05ba9fdd9f" Subject: Re: [PHP-DEV] [RFC] Warning for implicit float to int conversions From: benjamin.morel@gmail.com (Benjamin Morel) --00000000000064e19d05ba9fdd9f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sat, 6 Feb 2021 at 00:46, David Gebler wrote: > Generating a warning on explicit casts of (non-integer) floats to int > would IMO make no sense at all, it would put PHP at odds with other major > languages such as C, Python and Java and go against normal, reasonable > expectations of how a programming language behaves. > > You said in an earlier comment "it's better to be explicit about your > intent", but doing something like (int)3.5 *is* being explicit about your > intent - and truncating casts on float to int is the widely established > norm. > > This was exactly my reservation about deprecating this behaviour even as > an implicit cast - in my mind it isn't a bug or flaw, it's there by desig= n. > > If developers want to round/ceil/floor/do whatever with a float prior to > using it as an int, they already have that option and the greatest > flexibility. > > At least with the implicit case, I understand the motivation and argument > for bringing coercion more in line with strict typing behaviour and > catching cases where such a cast may not have been intentional (though I > still think a warning is too high an error level for this and would favou= r > a notice or deprecation, were it to be done at all). > Let's agree to disagree on what would be the ideal behaviour of type casts. I do understand that it would be a big concern for BC if (int) stopped working for floats with a fractional part. Could we at least fix the odd cases where the cast is definitely a failure? Like: (int) 1e60; // 0 (int) "foo"; // 0 =E2=80=94 Benjamin --00000000000064e19d05ba9fdd9f--