|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2016-12-31 00:36 UTC] cmb@php.net
-Package: Feature/Change Request
+Package: Variables related
[2018-09-05 23:28 UTC] carusogabriel@php.net
[2019-06-27 17:02 UTC] dwilks at intacct dot com
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 17:00:02 2025 UTC |
Description: ------------ I'm not sure whenever this is intended, but is_numeric() doesn't check if a value is numeric if the value is an object and has a magic __toString() method. I've created a patch and a test to illustrate this: Index: type.c =================================================================== RCS file: /repository/php-src/ext/standard/type.c,v retrieving revision 1.30.2.2.2.3.2.9 diff -u -r1.30.2.2.2.3.2.9 type.c --- type.c 21 Oct 2008 22:08:38 -0000 1.30.2.2.2.3.2.9 +++ type.c 8 Nov 2008 16:33:37 -0000 @@ -312,6 +312,11 @@ RETURN_TRUE; break; + case IS_OBJECT: + convert_to_string_ex(arg); + + /* Break intentionally missing */ + case IS_STRING: if (is_numeric_string(Z_STRVAL_PP(arg), Z_STRLEN_PP(arg), NULL, NULL, 0)) { RETURN_TRUE; And the test: /ext/standard/tests/misc/is_numeric_object.phpt --TEST-- is_numeric() should accept objects --FILE-- <?php class Test { public function __toString() { return('1337'); } } $test = new Test; var_dump(is_numeric($test)); ?> --EXPECT-- bool(true)