Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128249 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id E2A861A00BC for ; Mon, 28 Jul 2025 10:14:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1753697556; bh=z9fFipNEUw+yAPDB6iigQbIf+aKHck4OY5StBFTpCdM=; h=Date:To:From:Cc:Subject:In-Reply-To:References:From; b=JrfyMFuhxsZgNQgDogysXwXF8uLOqi6+KcOQfd5X+7hQ74Z5HT1Bu6CIGLgmGd10b F7T5uA/XCF71upKI1s67fpFslnuWQtI8de+Z+JrNdLib/YFfYDTkhJsJjRNvTHZAuS 2AicyrZlARavqcSLVz8a5KOW4URO0dy1TSgjG7FIzZ4YBv1Vxh/UILgeJ/3RNNukhE lwk4xQRVnJKHhtqDpJbWIbVdRyPQUmeC0Zidb/OQ/2GWdY5MAH1vWvR6saF9QODcHy 65LooCY+BDUie7JuC7JhNE2i81rPnHOtbhCM0vUNC7Q3LxRlLVA5a6lQt3P8XcLc+4 tKW3ZegC+POEw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1DA9D180069 for ; Mon, 28 Jul 2025 10:12:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from mail-10624.protonmail.ch (mail-10624.protonmail.ch [79.135.106.24]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 28 Jul 2025 10:12:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gpb.moe; s=protonmail; t=1753697654; x=1753956854; bh=z9fFipNEUw+yAPDB6iigQbIf+aKHck4OY5StBFTpCdM=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=xs03KKFWAHRwZr1cmrqFd9jjLErHBlPn0hXVxGfv/Rsy48GNAVZeSUm87AbVKIB8e xs2RECBQfrnFd4GzZzfpFbQX1y1aXZd7K/LeYeWgI3VkNERhWfkPCHVvmfrRunuIeO 4cO6LqnP2Tewon7RA87BYxDh8RECGbcEVgSPoHi+RhcVrIHh/82cqQUaiApJGoht7R IgLNXdMxlzFylkr6ySVH2kANQAtWWxhADVVHkleu+5LiHg+45EmswCxeRMYbH7KNkI VWeZLfsVdMmlzbSrS2hKWb5vk8Jq3rGKgawoKc8+9ot0Ja92gXiZ19e3R71OlAuVmG QL85e3gDscxmA== Date: Mon, 28 Jul 2025 10:14:08 +0000 To: Alexandre Daubois Cc: PHP internals list Subject: Re: [PHP-DEV] [DISCUSSION] Adding the "is_integer_safe()" function Message-ID: In-Reply-To: References: Feedback-ID: 96993444:user:proton X-Pm-Message-ID: cdbe75c1d548cf4fedf1088f0a4875fdd2d264e5 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: internals@gpb.moe ("Gina P. Banyard") On Friday, 25 July 2025 at 14:43, Alexandre Daubois wrote: > Hello Internals, >=20 > I would like to gather feedback on the proposal to add an > "is_integer_safe()" function to PHP. The idea came to me while > replying to a thread [1], but I think creating a discussion is more > appropriate. >=20 > Here are a few reasons I think this would be useful: >=20 > - PHP automatically converts integers that exceed PHP_INT_MAX to > float, which can cause undetected precision loss. This function would > allow checking that an integer remains within safe bounds before > critical operations ; > - Integer limits vary between 32-bit and 64-bit systems. This function > would provide a standardized way to check the portability of integer > values across different architectures ; > - This would improve code readability. We had the case in Symfony [2] > to implement a JSONPath crawler, and the solution feels hacky to say > the least ; > - PHP already has functions like `is_finite()` and `is_nan()` for > floats. Adding `is_integer_safe()` would logically complete this set > of type validation functions. > - Of course more optimized than dealing with strings and using > arithmetic operators on strings ; > - As PHP continues to evolve towards stricter type safety > (strict_types, typed properties, etc.), having more granular type > validation functions supports this direction. >=20 > If this proposition gets some interest, I'll take care of the > implementation in the engine. I guess it would also require an RFC. >=20 > Best, > Alex >=20 > [1] https://externals.io/message/128032 > [2] https://github.com/symfony/symfony/blob/d3a0df0243e1c68598fa066eaa6cd= 0cf39f256dc/src/Symfony/Component/JsonPath/JsonPathUtils.php#L243 Naming aside, I would be very much in favour of anything that makes it easi= er to make bidirectional transformations between floats and ints reliable. For naming, maybe the following pair of functions make sense? - is_representable_as_int() - is_representable_as_float() Best regards, Gina P. Banyard