#46524 [NEW]: is_numeric doesn't take objects as parameter
From: kalle@php.net
Operating system: Irrelevant
PHP version: 5.3.0alpha2
PHP Bug Type: Feature/Change Request
Bug description: is_numeric doesn't take objects as parameter
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)
--
Edit bug report at http://bugs.php.net/?id=46524&edit=1
--
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=46524&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=46524&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=46524&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=46524&r=fixedcvs
Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=46524&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=46524&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=46524&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=46524&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=46524&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=46524&r=support
Expected behavior: http://bugs.php.net/fix.php?id=46524&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=46524&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=46524&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=46524&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=46524&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=46524&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=46524&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=46524&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=46524&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=46524&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=46524&r=mysqlcfg
Thread (3 messages)
- kalle@php.net