Req #46524 [Com]: is_numeric doesn't take objects as parameter

From: Date: Wed, 05 Sep 2018 23:28:25 +0000
Subject: Req #46524 [Com]: is_numeric doesn't take objects as parameter
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-216904@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=46524&edit=1 ID: 46524 Comment by: carusogabriel@php.net Reported by: kalle@php.net Summary: is_numeric doesn't take objects as parameter Status: Open Type: Feature/Change Request Package: Variables related Operating System: Irrelevant PHP Version: 5.3.0alpha2 Block user comment: N Private report: N New Comment: IMO we can also expand other functions, like is_string to also support objects, witch current it doesn't: https://3v4l.org/R1kJr I'm gonna be expanding the proposed patch and open for discussion in GitHub/internals@ mailing list. Previous Comments: ------------------------------------------------------------------------ [2008-11-08 20:04:55] kalle@php.net 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 this bug report at https://bugs.php.net/bug.php?id=46524&edit=1

« previous php.bugs (#216904) next »