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
 [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: Mon Dec 08 09:00:01 2025 UTC