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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-12-19 10:59 UTC]
Automatic comment from SVN on behalf of degeberg
Log: Fixed #50311.
 [2009-12-19 11:00 UTC]
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]
Automatic comment on behalf of degeberg
Log: Fixed #50311.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Mon Mar 27 06:03:38 2023 UTC