Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128228 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 E21711A00BC for ; Fri, 25 Jul 2025 13:41:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1753450757; bh=zIjl3tDBeQgZ/1uJkqdjENTD6YXkhEW4HWbKdRom37k=; h=From:Date:Subject:To:From; b=YMHTVagyfI1JKaIKeOdZydY+rmU83kIJdgERDONPFKTdxaROHtGaLFGgVrnI2kycF ryfOXaVnCwXihV1+Rs/gA7rGs4/qppe1KmUEOHuPS9vG0mhpheMUg/hlMJIt/RMRTq rJHs8n9tcGr4FoBzcZuuQ8W10fTWoDFJ821rfE9FYLQ3gWC2V8hrruMm/egJSy92sS 0EKMlKpjzcxxpr9U0tO9wYwopfjSoSRmbSEK2plvl/cthuO0nJv57pqPaOimxiX5P/ Mc4MvUsTKHzpV5StgaEbxwUlRHwMQaZ210ZfzN89TZLu+OATbhjpGMgVT5iqTp9qCg Y9RSt1aegFNzQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 893541801EB for ; Fri, 25 Jul 2025 13:39:16 +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=-1.2 required=5.0 tests=BAYES_40,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,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-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) (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 ; Fri, 25 Jul 2025 13:39:16 +0000 (UTC) Received: by mail-ed1-f48.google.com with SMTP id 4fb4d7f45d1cf-60768f080d8so4139064a12.1 for ; Fri, 25 Jul 2025 06:41:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1753450859; x=1754055659; darn=lists.php.net; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=zIjl3tDBeQgZ/1uJkqdjENTD6YXkhEW4HWbKdRom37k=; b=K/0TpkwxWnAkhjNo6N0H3k8eKR1K1Jfh+/4N9TBzhsX3ZV4kvAmvVac2ZAB/GPnw/V lpTs7AFaFkxjutqgXj58JWFtOzpDKqTPgE72zDqeNDnDdc4DqT13g+RXyVsAPx5vVaNe e2GTsWt60aEAqTGvO1ih2XdttO9jUTwYlmxMdl1XZhe5PLNLj7wh1OFIIHgBqFHXrC3o cucgp0v+qGajEYY95iO2FZ+L3dSkR33Yo/Pfxi3iOkAg55wTafGlKNB0Ha0WdQnxqHKz 7AGR+isXzF/k5VwSqSCozKJ0tIwaftXFKvCH/V1u+3urNL8wCmMaNbHa6hSDIW6Gagt4 6AEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753450859; x=1754055659; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=zIjl3tDBeQgZ/1uJkqdjENTD6YXkhEW4HWbKdRom37k=; b=Yr3FtJWziZQo9t0fx/M9GAe5ieznrU166h0ULygwVXkVP1Sl/6TAvgFsyRTbTjgNx3 oe3lQQUwgfHy7PoqCKQ8ybi9Q9BShv2hCGLj99Kk6ZuOxJP8YnSNwNcRaelWhtz+1Yg5 tcPVIZNOyCLNAnVy6oVLRXlpXh3InajPrN6Ea6NZRAC3RQw7Le45XeOr8Qi+akEMwVss buJYU2Dw4kvq5e4/Hwc6S3auAZM3jFu7gZqn7QMWJ6f8Xil2u2Iv6cMiLhPo3MYi/1j8 MHM1JoODLUfz0FMtBij5fxx1OjtItiJ3yTJbb+IVncmDD3dep6Ck0nFHugH+e+cQKJHy lVpg== X-Gm-Message-State: AOJu0YzWROtwZEOHERbyUzAL5gdGB1Ni52ndMv3ZUBLqKYk0X23z+4d9 t2Vv8NSCYACjrwecnxk1IsY2sgYmfQhOYFsOo9ylzY9Yq9E4QUScn7bF5O1eIdCuwhaQ6mmy5EQ N6cCPWAVToV2l+OM4yJ2Nle2OY2LYMXWDOL6U X-Gm-Gg: ASbGncu2favc//T5AOlu2cgMybAjuFyl/WdA79r+gNZwnYpx5CQYpGPO+4HBXRl0UJv fDHZCADp7pDiok/ZU3EArStc3G4zix9gp+RWYNMjKioRpWzxDe0i0AYODGEp+tPeWNzKQICWgWp P038EWgqKyNbCzlkub1XVyuVy4ptJ3afSCUWJwpq/EU0HKMwbWQa0RTVetAvmTOgWMyPxBjA1AB LRgeNZER+DzuyQ5ANOvW+2h0zVBCxcEpW9vMscL X-Google-Smtp-Source: AGHT+IGh+TWPLHbwhuNV+jseZ6coTyBLVpjGtnrUhG5M9YnjlUShX1YTPJF4F7Wopz+ZkHx75Ywjx9BYlIYZxA/CS6Y= X-Received: by 2002:a05:6402:2356:b0:608:50ab:7e38 with SMTP id 4fb4d7f45d1cf-614f1d3ad72mr1685025a12.14.1753450858646; Fri, 25 Jul 2025 06:40:58 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Fri, 25 Jul 2025 15:40:47 +0200 X-Gm-Features: Ac12FXyT1uRwkqf6Gd8DTL5UXKgSy95twQow1r27OQ0aqHrMZwZWeCG0fCMghAY Message-ID: Subject: [PHP-DEV] [DISCUSSION] Adding the "is_integer_safe()" function To: PHP internals list Content-Type: text/plain; charset="UTF-8" From: alex.daubois+php@gmail.com (Alexandre Daubois) Hello Internals, 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. Here are a few reasons I think this would be useful: - 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. If this proposition gets some interest, I'll take care of the implementation in the engine. I guess it would also require an RFC. Best, Alex [1] https://externals.io/message/128032 [2] https://github.com/symfony/symfony/blob/d3a0df0243e1c68598fa066eaa6cd0cf39f256dc/src/Symfony/Component/JsonPath/JsonPathUtils.php#L243