php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #22173 Strange behaviour with the string 'inf'
Submitted: 2003-02-11 13:55 UTC Modified: 2003-02-16 10:50 UTC
Votes:4
Avg. Score:4.0 ± 1.2
Reproduced:4 of 4 (100.0%)
Same Version:1 (25.0%)
Same OS:2 (50.0%)
From: afenoy at wol dot es Assigned:
Status: Wont fix Package: Scripting Engine problem
PHP Version: 4.3.1-dev OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2003-02-11 13:55 UTC] afenoy at wol dot es
Very strange bug: (double) of any string begining with 'inf'  evaluates as 'INF', but only in strings of more than 3 characters a comparison with a integer results in same bug. 

Try this script:

<?
echo 'somestring'   > 1 ? 1 : 0, '<br>';
echo 'inf'          > 1 ? 1 : 0, '<br>';
echo 'info'         > 1 ? 1 : 0, '<br>';
echo 'inf at begin' > 1 ? 1 : 0, '<br>';
echo (double)'somestring',   '<br>';
echo (double)'inf',          '<br>';
echo (double)'inf at begin', '<br>';
?>

Expected results are:

0
0
0
0
0
0
0

But real results are:

0
0
1
1
0
INF
INF

Saludos
?ngel

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-02-11 17:11 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

When performing a mathematical calculation between a number and a string in PHP, PHP will attempt to convert the string to an integer. Since PHP supports things such as INF certain strings, such as 'inf more data' will be converted to INF.
 [2003-02-12 04:38 UTC] afenoy at wol dot es
Ok, double-checked the documentation: this behavior of 'inf...' strings seems absolutely undocumented.

Auto-convertion of any string that begins by 'inf' in infinite seems to me inadequate. Considering that this 'functionality' has not been documented, would be desirable to create a new predefined constant INF or a new data type INF or a new reserved word INF to treat infinite numbers, in the same form in which NULL, TRUE or FALSE correspond to 
predefined values. Consider that when we locked up 'NULL', 'TRUE' or 'FALSE' in a string, they are not evaluated like the corresponding constants. The same behavior would be desirable with a (new) predefined constant INF.

And at least an error exists now in the form in which the strings that begin by 'inf' are treated. The strings of more than 3 characters ('information', 'infant' ...) are evaluated as INF in the comparisons with numbers, but the string 'inf', with single three characters, does not. Try this:

<?
echo (double)'information', '<br>';
echo (double)'inf'        , '<br>';

echo 'information' > 1 ? 1 : 0, '<br>';
echo 'inf'         > 1 ? 1 : 0, '<br>';
?>

Result:

INF
INF
1
0

Saludos
?ngel
 [2003-02-12 05:16 UTC] afenoy at wol dot es
Re-open: at least with single three characters 'inf', this is a bug and not a 'functionality'.
 [2003-02-12 12:46 UTC] helly@php.net
We're already discussing this - so reopening was valid.
 [2003-02-12 22:02 UTC] sniper@php.net
verified with PHP 4.3.1-dev..

 [2003-02-16 10:50 UTC] iliaa@php.net
This bug is the result of differing implementations of strtod() in the various libc libraries. For example glibc considers (double) "info" to be equivalent to INF while in Win32 the same operation will return 0.
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Wed Jul 06 00:05:46 2022 UTC