php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #8803 crazy implementation of printf/sprintf
Submitted: 2001-01-19 10:07 UTC Modified: 2001-01-19 10:10 UTC
From: mikeb at gbdirect dot co dot uk Assigned:
Status: Closed Package: Unknown/Other Function
PHP Version: 4.0.4pl1 OS: Linux
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mikeb at gbdirect dot co dot uk
New email:
PHP Version: OS:

 

 [2001-01-19 10:07 UTC] mikeb at gbdirect dot co dot uk
Whether a bug or a feature, I consider it a serious bug that printf/sprintf
do not fully adhere to the formatting rules set out in ANSI/ISO C documentation. In particular, I have just wasted the better part of a day discovering that code which used %.2x to format a 2-digit hex number
(worked fine in php3) now just prints nothing using 4.04pl1

Surely the formatting is done using the underlying sprintf function anyhow? If not, then php really should not call this function sprintf() but something that indicates that is not the same.

Just my opinion, but it has been very frustrating and seems an unneccessary difference.

Mike Banahan

Sample code:

<?
printf(":%.2x:\n", 14);
?>

Sample output:

X-Powered-By: PHP/4.0.4pl1
Content-type: text/html
 
:: 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-01-19 10:10 UTC] derick@php.net
This works fine:

echo sprintf ("%2x", 29);

output:
1d

This is not a bug.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 21:01:29 2024 UTC