note 55240 deleted from function.is-numeric by crell

From: Date: Mon, 18 Apr 2022 14:59:42 +0000
Subject: note 55240 deleted from function.is-numeric by crell
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-218291@lists.php.net to get a copy of this message
Note Submitter: sebu ---- Referring to previous post "Be aware if you use is_numeric() or is_float() after using set_locale(LC_ALL,'lang') or set_locale(LC_NUMERIC,'lang')": This is totally wrong! This was the example code: ----- set_locale(LC_NUMERIC,'fr'); is_numeric(12.25); // Return False is_numeric(12,25); // Return True is_float(12.25); //Return False is_float(12,25); //Return True ----- This is nonsense! - set_locale() does not exist, you must use setlocale() instead - you have to enclose 12,25 with quotes; otherwise PHP will think that the function gets _two_ arguments: 12 and 25 (depending on PHP version and setup you may additionally get a PHP warning) - if you don't enclose 12,25 with quotes the first argument will be the inspected value (12), the second value (25) is discarded. And is_numeric(12) and is_float(12) is always TRUE Corrected Example: ---- setlocale(LC_NUMERIC,'fr'); is_numeric(12.25); // Return True is_numeric("12,25"); // Return False is_float(12.25); //Return True is_float("12,25"); //Return False ---- Remarks: - is_float(12.25) is _always_ TRUE, 12.25 is a PHP language construct (a "value") and the way PHP interpretes files is definitely _not_ affected by the locale - is_float("12,25") is _always_ FALSE, since is_float (other than is_numeric): if the argument is a string then is_float() always returns FALSE since it does a strict check for floats And the corrected example shows: you get the _same_ results for every possible locale, is_numeric() does not depend on the locale.

« previous php.notes (#218291) next »