php.net |  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
Votes:1
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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ilyes dot ahidar at gmail dot com
New email:
PHP Version: OS:

 

 [2021-01-14 16:21 UTC] ilyes dot ahidar at gmail dot com
Description:
------------
---
From manual page: https://php.net/function.abs
---

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:
---------------
<?php

declare(strict_types=1);

$a = "0.00";

var_dump(abs($a));

Expected result:
----------------
In php 7 it would output:

float(0)

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

Patches

Pull Requests

Pull requests:

History

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

Patch Name: Generate some standard methodsynopses based on stubs
On GitHub:  https://github.com/php/doc-en/pull/289
Patch:      https://github.com/php/doc-en/pull/289.patch
 [2021-05-23 11:27 UTC] cmb@php.net
-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

https://www.php.net/manual/en/migration80.incompatible.php
https://www.php.net/manual/en/migration80.deprecated.php
https://www.php.net/manual/en/migration80.other-changes.php

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.

<?php
$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:

<?php
$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] cmb@php.net
<https://3v4l.org/DXrcp> 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] <https://www.php.net/manual/en/language.types.numeric-strings.php>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Nov 11 17:01:29 2024 UTC