php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #63928 unexpected behaviour of sprintf
Submitted: 2013-01-07 09:19 UTC Modified: 2013-01-07 10:27 UTC
From: Mikayuoads at gmail dot com Assigned:
Status: Wont fix Package: Unknown/Other Function
PHP Version: 5.4.10 OS: Gentoo
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: Mikayuoads at gmail dot com
New email:
PHP Version: OS:

 

 [2013-01-07 09:19 UTC] Mikayuoads at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.sprintf#refsect1-function.sprintf-seealso
---

Right padding doesn't work with zeros.

Test script:
---------------
echo sprintf('%\'0-5d', 42); // output: '42   '
echo sprintf('%0-5d', 42); // output: '42   '
echo sprintf('%\'#-5d', 42); // output: '42###'

Expected result:
----------------
expected result:
echo sprintf('%\'0-5d', 42); // output: '42000'
echo sprintf('%0-5d', 42); // output: '42000'
echo sprintf('%\'#-5d', 42); // output: '42###'


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-01-07 10:27 UTC] cataphract@php.net
-Status: Open +Status: Wont fix
 [2013-01-07 10:27 UTC] cataphract@php.net
The sprintf() function specified for the C standard, and upon which PHP's function is based explicitly says that "[i]f the 0 and-flags both appear, the 0 flag is ignored."

Implementing different behavior in PHP would be ill-advised.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 11:01:32 2025 UTC