Bug #74422 [Ana->Csd]: Round function returns false for non-numeric argument

From: Date: Thu, 31 Oct 2019 10:19:09 +0000
Subject: Bug #74422 [Ana->Csd]: Round function returns false for non-numeric argument
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-223529@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74422&edit=1 ID: 74422 Updated by: nikic@php.net Reported by: jose dot carlos dot garcia dot 95 at gmail dot com Summary: Round function returns false for non-numeric argument -Status: Analyzed +Status: Closed Type: Bug Package: *Math Functions Operating System: Ubuntu PHP Version: 7.0Git-2017-04-12 (Git) -Assigned To: +Assigned To: nikic Block user comment: N Private report: N New Comment: round([]) will throw a TypeError in PHP 8. Both false and null will no longer be possible return values. Previous Comments: ------------------------------------------------------------------------ [2019-10-30 23:07:20] puggan at sundragon dot se The false as return value is mention for floor([]), but not for ceil([]) or round([]). If its worth mention on floor, shouldn't it be mention on the others? (Or should it be removed from floor?) ------------------------------------------------------------------------ [2017-04-17 08:44:16] jose dot carlos dot garcia dot 95 at gmail dot com Yes, make a correction in documentation could be nice too! But I think is necessary make an advertency that round would return a non-float value. ------------------------------------------------------------------------ [2017-04-14 09:18:25] cmb@php.net > But, if I try with a string or a boolean value, round return 0 > and not false, so it's strange. That is because the argument is converted to a number[1] and only if that fails, FALSE is returned[2]. Changing that to return NULL is trivial, but would be a BC break for not much gain. Perhaps it's better to fix the documentation instead. [1] <https://github.com/php/php-src/blob/php-7.1.4/ext/standard/math.c#L379> [2] <https://github.com/php/php-src/blob/php-7.1.4/ext/standard/math.c#L396> ------------------------------------------------------------------------ [2017-04-12 20:20:26] jose dot carlos dot garcia dot 95 at gmail dot com But, if I try with a string or a boolean value, round return 0 and not false, so it's strange. I think that null value is a good option. ------------------------------------------------------------------------ [2017-04-12 20:15:11] requinix@php.net Typically built-in functions return NULL when given an argument of the wrong type, but returning false is also permitted. http://php.net/manual/en/functions.internal.php Looks like round RETURN_FALSEs for values that aren't int or float. It should be fine to change that, right? ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=74422 -- Edit this bug report at https://bugs.php.net/bug.php?id=74422&edit=1

« previous php.bugs (#223529) next »