|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #80624 Undocumented change php 8 vs php 7 abs function
Submitted: 2021-01-14 16:21 UTC Modified: 2022-05-11 10:51 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: ilyes dot ahidar at gmail dot com Assigned: cmb (profile)
Status: Closed Package: *Math Functions
PHP Version: 8.0.1 OS: Linux Fedora 33
Private report: No CVE-ID: None
 [2021-01-14 16:21 UTC] ilyes dot ahidar at gmail dot com
From manual page:

The manual says that the abs() function accepts 1 argument of the type "mixed", but enabling strict_types and passing a string to the abs function outputs an type error.

Test script:


$a = "0.00";


Expected result:
In php 7 it would output:


Actual result:
Fatal error: Uncaught TypeError: abs(): Argument #1 ($num) must be of type int|float, string given in /in/ZD7Kd:7
Stack trace:
#0 /in/ZD7Kd(7): abs('0.00')
#1 {main}
  thrown in /in/ZD7Kd on line 7


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-01-14 16:53 UTC]
-Status: Open +Status: Verified
 [2021-01-14 16:54 UTC]
The following pull request has been associated:

Patch Name: Generate some standard methodsynopses based on stubs
On GitHub:
 [2021-05-23 11:27 UTC]
-Status: Verified +Status: Closed -Assigned To: +Assigned To: cmb
 [2021-08-18 16:35 UTC] kawewong at gmail dot com
This also is not in these pages

I could not find info about this and just let my php run until one day there are unknown errors and I find out that it is incompatible.

$num = '1.00';
var_dump(abs($num));// working fine until PHP 8.0+

Maybe please update any one of these page.
 [2022-05-11 10:20 UTC] post at andreas-mause dot de
It's only a problem on empty string-values:

$num = '';
var_dump(abs($num));// working not until PHP 8.0+

But "" is a string, so it should working ... so it's a bug?!
 [2022-05-11 10:51 UTC]
<> reports

| abs(): Argument #1 ($num) must be of type int|float, string given

In coercive type mode (the default) a string is juggled to an
int|float, if it is numeric[1].  An empty string is not considered
to be numeric.

[1] <>
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Feb 21 03:01:33 2024 UTC