php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #50311 intval() vs floatval(): same behavior but different documentation
Submitted: 2009-11-27 12:13 UTC Modified: 2009-12-19 11:00 UTC
From: php-qa at sebastianmendel dot de Assigned:
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
48 - 6 = ?
Subscribe to this entry?

 
 [2009-11-27 12:13 UTC] php-qa at sebastianmendel dot de
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



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-12-19 10:59 UTC] svn@php.net
Automatic comment from SVN on behalf of degeberg
Revision: http://svn.php.net/viewvc/?view=revision&revision=292325
Log: Fixed #50311.
 [2009-12-19 11:00 UTC] degeberg@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 [2020-02-07 06:09 UTC] phpdocbot@php.net
Automatic comment on behalf of degeberg
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=206956db6821c8c01337b00b06d84b9df7b840c4
Log: Fixed #50311.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 11:01:28 2024 UTC