ID: 3443
Updated by: [EMAIL PROTECTED]
Reported By: [EMAIL PROTECTED]
-Status: Open
+Status: Closed
Bug Type: Misbehaving function
Operating System: RH Linux 6.1
PHP Version: 3.0.14
New Comment:
fixed in php4
Previous Comments:
------------------------------------------------------------------------
[2000-02-10 01:35:06] [EMAIL PROTECTED]
This is a really strange problem, but sprintf seems to be padding a
null character to the end of a string when the string consists of a
negative float. Here is a script that will reproduce the problem:
<?
$string = -122.440383;
$new_string = sprintf("%0.6f", $string);
echo "string = $string<br>\n";
echo "new_string = $new_string<br>\n";
for ($j=0;$j<strlen($new_string);$j++) {
echo "letter #$j: " . ord($new_string[$j]) . "<br>\n";
}
?>
The output on php-3.0.14, php-3.0.13, php-4.0b3 looks like:
string = -122.440383
new_string = -122.440383
letter #0: 45
letter #1: 49
letter #2: 50
letter #3: 50
letter #4: 46
letter #5: 52
letter #6: 52
letter #7: 48
letter #8: 51
letter #9: 56
letter #10: 51
letter #11: 0
There is no null character at the end if the float is positive.
I noticed that php-3.0.12 doens't exhibit this behavior. The way I
configured all these different versions of php was:
Configure command: ./configure '--with-mhash' '--with-mcrypt'
'--disable-display-source' '--enable-debugger' '--enable-track-vars'
'--enable-debug' '--with-xml' '--with-oracle' '--without-gd'
'--with-apxs=../www/bin/apxs'
The one major difference I know between my versions of php-3.0.12 and
the others is that 3.0.12 compiles against an older version of mcrypt
and all these others compile against a newwr version. This is probably
irrelevant because I have no idea what mcrypt libraries would have to
do with sprintf, but I thought I'd mention it.
Thanks.
-Greg
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=3443&edit=1