|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #46524 is_numeric doesn't take objects as parameter
Submitted: 2008-11-08 20:04 UTC Modified: 2016-12-31 00:36 UTC
Avg. Score:3.0 ± 1.4
Reproduced:2 of 3 (66.7%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: Assigned:
Status: Open Package: Variables related
PHP Version: 5.3.0alpha2 OS: Irrelevant
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
New email:
PHP Version: OS:


 [2008-11-08 20:04 UTC]
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
diff -u -r1. type.c
--- type.c	21 Oct 2008 22:08:38 -0000
+++ type.c	8 Nov 2008 16:33:37 -0000
@@ -312,6 +312,11 @@
+		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)) {

And the test:

is_numeric() should accept objects
class Test
	public function __toString()

$test = new Test;


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-12-31 00:36 UTC]
-Package: Feature/Change Request +Package: Variables related
 [2018-09-05 23:28 UTC]
IMO we can also expand other functions, like `is_string` to also support objects, witch current it doesn't:

I'm gonna be expanding the proposed patch and open for discussion in GitHub/internals@ mailing list.
 [2019-06-27 17:02 UTC] dwilks at intacct dot com
Please look at also.  It's of the same type, trying to pass an extension-based class instance into a bool parameter.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Jul 19 04:01:28 2024 UTC