php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #24872 sprintf() returns trailing NULL character
Submitted: 2003-07-30 09:56 UTC Modified: 2003-07-30 11:40 UTC
From: kostas at nasis dot com Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.3.2 OS: Redhat 7.3, 8
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: kostas at nasis dot com
New email:
PHP Version: OS:

 

 [2003-07-30 09:56 UTC] kostas at nasis dot com
Description:
------------
sprintf() will return a trailing NULL character under certain conditions. See code below.

Reproduce code:
---------------
<?php
    $blah = sprintf("%04d", -500);

    echo "$blah\n";

    // display ASCII code for each character of $blah
    for ($i = 0; $i < strlen($blah); $i++) {
        echo ord($blah{$i}) . "\n";
    }
?>


Expected result:
----------------
The code should output:
-500
45
53
48
48



Actual result:
--------------
On PHP v4.3.2 it outputs:
-500
45
53
48
48
0

Notice the NULL (0) character at the end.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-07-30 11:40 UTC] sniper@php.net
Seems to be fixed in CVS since I get the expected result.

 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Dec 10 17:00:01 2025 UTC