php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80018 Tests expect var_dump(FLOAT) to print an integer
Submitted: 2020-08-25 20:09 UTC Modified: 2020-08-25 20:32 UTC
From: jamieliu at google dot com Assigned:
Status: Closed Package: Testing related
PHP Version: master-Git-2020-08-25 (Git) OS: All
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jamieliu at google dot com
New email:
PHP Version: OS:

 

 [2020-08-25 20:09 UTC] jamieliu at google dot com
Description:
------------
Many tests parse the result of var_dump() on a float and expect the result to be an integer:

$ find . -name '*.phpt' | xargs grep 'float(%d)'
./Zend/tests/cast_to_double.phpt:float(%d)
./Zend/tests/settype_double.phpt:float(%d)
./ext/standard/tests/file/disk_total_space_basic.phpt:float(%d)
./ext/standard/tests/file/disk_total_space_basic.phpt:float(%d)
./ext/standard/tests/file/disk_total_space_basic.phpt:float(%d)
./ext/standard/tests/file/disk_free_space_variation.phpt:float(%d)
./ext/standard/tests/file/disk_free_space_variation.phpt:float(%d)
./ext/standard/tests/file/disk_free_space_variation.phpt:float(%d)
./ext/standard/tests/file/disk_free_space_variation.phpt:float(%d)
./ext/standard/tests/file/disk_free_space_variation.phpt:float(%d)
./ext/standard/tests/file/disk_free_space_variation.phpt:float(%d)
./ext/standard/tests/file/disk_free_space_variation.phpt:float(%d)
./ext/standard/tests/file/disk_free_space_variation.phpt:float(%d)
./ext/standard/tests/file/disk_free_space_variation.phpt:float(%d)
./ext/standard/tests/file/disk_free_space_variation.phpt:float(%d)
./ext/standard/tests/file/disk_free_space_variation.phpt:float(%d)
./ext/standard/tests/file/disk_free_space_variation.phpt:float(%d)
./ext/standard/tests/file/disk_free_space_variation.phpt:float(%d)
./ext/standard/tests/file/disk_free_space_variation.phpt:float(%d)
./ext/standard/tests/file/disk_free_space_variation.phpt:float(%d)
./ext/standard/tests/file/disk_free_space_variation.phpt:float(%d)
./ext/standard/tests/file/disk_free_space_variation.phpt:float(%d)
./ext/standard/tests/file/disk_free_space_variation.phpt:float(%d)
./ext/standard/tests/file/disk.phpt:float(%d)
./ext/standard/tests/file/disk.phpt:float(%d)
./ext/standard/tests/file/disk_total_space_error.phpt:float(%d)
./ext/standard/tests/file/disk_free_space_error.phpt:float(%d)
./ext/standard/tests/file/disk_free_space_error.phpt:float(%d)
./ext/standard/tests/file/disk_free_space_basic.phpt:float(%d)
./ext/standard/tests/file/disk_free_space_basic.phpt:float(%d)
./ext/standard/tests/file/disk_free_space_basic.phpt:float(%d)
./ext/standard/tests/file/disk_free_space_basic.phpt:float(%d)
./ext/standard/tests/file/disk_free_space_basic.phpt:float(%d)
./ext/standard/tests/file/disk_total_space_variation.phpt:float(%d)
./ext/standard/tests/file/disk_total_space_variation.phpt:float(%d)
./ext/standard/tests/file/disk_total_space_variation.phpt:float(%d)
./ext/standard/tests/file/disk_total_space_variation.phpt:float(%d)
./ext/standard/tests/file/disk_total_space_variation.phpt:float(%d)
./ext/standard/tests/file/disk_total_space_variation.phpt:float(%d)
./ext/standard/tests/file/disk_total_space_variation.phpt:float(%d)
./ext/standard/tests/file/disk_total_space_variation.phpt:float(%d)
./ext/standard/tests/file/disk_total_space_variation.phpt:float(%d)
./ext/standard/tests/general_functions/type.phpt:float(%d)
./ext/standard/tests/general_functions/type.phpt:float(%d)
./ext/standard/tests/general_functions/type.phpt:float(%d)
./ext/standard/tests/general_functions/gettype_settype_basic.phpt:float(%d)
./ext/standard/tests/general_functions/gettype_settype_basic.phpt:float(%d)
./ext/standard/tests/general_functions/gettype_settype_basic.phpt:float(%d)
./ext/standard/tests/general_functions/gettype_settype_basic.phpt:float(%d)

This is problematic because var_dump() will print sufficiently large numbers in exponential notation. An example in Linux:

$ mkdir tmp
$ sudo mount -t tmpfs -o size=$((1 << 62)) tmpfs tmp
$ ~/src/php-src/sapi/cli/php --version
PHP 8.0.0-dev (cli) (built: Aug 25 2020 12:55:38) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies
$ ~/src/php-src/sapi/cli/php -r 'var_dump(disk_total_space("tmp"));'
float(4.611686018427388E+18)

I think every instance of "float(%d)" in such tests could simply be converted to use "float(%E)" instead.

Test script:
---------------
See description.


Patches

0001-Tolerate-var_dump-printing-floats-in-exponential-not.patch (last revision 2020-08-25 20:52 UTC by jamieliu at google dot com)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-08-25 20:32 UTC] cmb@php.net
I agree that this should be fixed, but to my knowledge
run-tests.php does not support %E, but only %f.  Are you using
another test runner?
 [2020-08-25 20:50 UTC] jamieliu at google dot com
My mistake, I though test format strings were interpreted by sscanf(). Using %f instead seems to work (tested by modifying ext/standard/tests/file/disk.phpt to call disk_free_space() and disk_total_space() on a tmpfs mount as described in the original report).
 [2020-08-25 20:52 UTC] jamieliu at google dot com
The following patch has been added/updated:

Patch Name: 0001-Tolerate-var_dump-printing-floats-in-exponential-not.patch
Revision:   1598388759
URL:        https://bugs.php.net/patch-display.php?bug=80018&patch=0001-Tolerate-var_dump-printing-floats-in-exponential-not.patch&revision=1598388759
 [2020-08-31 07:51 UTC] nikic@php.net
Automatic comment on behalf of jamieliu@google.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=c8093fe94a0bfa6aff3ead29744fb20d7c60c07b
Log: Fix bug #80018: Tolerate var_dump() printing floats in exponential notation in tests
 [2020-08-31 07:51 UTC] nikic@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jan 15 15:01:31 2025 UTC