#50311 [NEW]: intval() vs floatval(): same behavior but different documentation
| From: | php-qa at sebastianmendel dot de | Date: | Fri, 27 Nov 2009 12:13:49 +0000 |
| Subject: | #50311 [NEW]: intval() vs floatval(): same behavior but different documentation | ||
| Groups: | php.doc.bugs | ||
| Request: | Send a blank email to doc-bugs+get-3347@lists.php.net to get a copy of this message | ||
From: php-qa at sebastianmendel dot de
Operating system:
PHP version: Irrelevant
PHP Bug Type: Documentation problem
Bug description: intval() vs floatval(): same behavior but different documentation
Description:
------------
the parameter and return description for floatval() and intval() differs
but both behave exactly the same way
floatval(): var - May be any scalar type. You cannot use floatval() on
arrays or objects.
intval(): var - The scalar value being converted to an integer
Return Values: [...] Empty arrays and objects return 0, non-empty arrays
and objects return 1.
but both functions are accepting array as var and throw notice on objects
Reproduce code:
---------------
echo intval(array()); // 0
echo intval(array(1,2,3)); // 1
echo intval(new stdClass); // 1
Notice: Object of class stdClass could not be converted to int in php
shell code on line 1
echo floatval(array()); // 0
echo floatval(array(1,2,3)); // 1
echo floatval(new stdClass); // 1
Notice: Object of class stdClass could not be converted to double in php
shell code on line 1
--
Edit bug report at http://bugs.php.net/?id=50311&edit=1
--
Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=50311&r=trysnapshot52
Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=50311&r=trysnapshot53
Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=50311&r=trysnapshot60
Fixed in SVN: http://bugs.php.net/fix.php?id=50311&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=50311&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=50311&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=50311&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=50311&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=50311&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=50311&r=support
Expected behavior: http://bugs.php.net/fix.php?id=50311&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=50311&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=50311&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=50311&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=50311&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=50311&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=50311&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=50311&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=50311&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=50311&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=50311&r=mysqlcfg