Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128566 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 616321A00C1 for ; Tue, 26 Aug 2025 18:36:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1756233276; bh=mFx+8f1/6fY00Qo+TqMihd0haEsXCThoogpKn3HaLyw=; h=Date:Subject:To:References:From:In-Reply-To:From; b=evVPseiKY88SZpcen/coVFz2eVPhKliydeY7XyFXfxw/fNOg+3Fpy6ygRhDhx9CzP cVN7IXnVBZ0xjHnwek3uYLZEVJxap2OezfuvA5qBBhoBbjoXBZChhnHPbamEPzZR3O 7/BnkAVMznVfwcQBFtsqJfV7RIU5gByc4lzX78brFQgtvDvVh1Gmr+fUdvTBqK3evE X+xXojUlSbXY9dyU6D+U8iF+H/ZuMmSzYy3lV7z3unsVL5EKeH5wn/CwLv4ODLA1jG uGwKuq9bbcR1BAdYTyxoVpAh45w/VkchWHswjWEtT6lOAYbvpgFnYuEpsnrv7V34fQ 6r+NWg7J2628A== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C78321801DF for ; Tue, 26 Aug 2025 18:34: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=-0.7 required=5.0 tests=BAYES_05,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (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 ; Tue, 26 Aug 2025 18:34:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1756233363; bh=nuIe7U0b/eBTURF8b2vdtEQlzFQQ3pZGU7bKkbZG1Ag=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type:from:to:cc:subject:message-id; b=C+yMorfY4358uf7WcF+TJjvx61l5V6H8Y9ayGz8VfpJopMnCQ92COSYli7eQJxW8v Oj+Kuuj3H1NVLI8CacThr7qu0YzLHziBHhO3D4Jg1WjjK0UQjUPSualLlgnXjJ/M6N AA3EQEBv6nERWnHgvqKORAiIkFE1P8ZzNDEY22qOVhQUgtmRljIaPj3KZ09RpSzf3v sdFoQocOOi8Ua6cPkqn0cJ4X8rYy5eEFWD4k0yi3asuLT4q8Ji0++wH7sIXPtUwLKd k/bUkizKz2+KFLsVwFTCrQndEyroZAYJeigwZtUYAZzHROnPAu9okTKWAbLzRhDFvv AHecHeEQLZBxA== Message-ID: <642a1575-a855-442a-aa3c-3fa123e793d7@bastelstu.be> Date: Tue, 26 Aug 2025 20:36:01 +0200 Precedence: list list-help: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 Subject: Re: [PHP-DEV] [RFC] Add "is_representable_as_float()" and "is_representable_as_int()" functions To: Larry Garfield , php internals References: Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=C3=BCsterhus?=) Hi On 8/26/25 16:48, Larry Garfield wrote: > I have multiple times just recently had need of "I have a numeric string, should I cast it to an int or a float?", for which an is_representable_as_int() function (or similar) would be quite helpful, and neater than the messy solution I usually use. It would've been nice to know what that use-case is, rather than just knowing that you had that use-case. I'm having a hard time thinking of something where I don't a-priori know what type I expect to get and would need to inspect the value to make a decision. I see how having a function that safely coerces a string into an int, returning null if coercion fails, basically intval() with better error handling and taking only `string`s, could be useful, but that's not what is being asked here. Best regards Tim Düsterhus