|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #49802 Irritating error message when passing irregular arguments for parsing (sprintf)
Submitted: 2009-10-07 12:45 UTC Modified: 2010-12-20 09:16 UTC
Avg. Score:3.0 ± 1.3
Reproduced:9 of 9 (100.0%)
Same Version:1 (11.1%)
Same OS:4 (44.4%)
From: timm dot forallthestuff at web dot de Assigned:
Status: Open Package: Strings related
PHP Version: 5.3.0 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: timm dot forallthestuff at web dot de
New email:
PHP Version: OS:


 [2009-10-07 12:45 UTC] timm dot forallthestuff at web dot de
The error message displayed by php is irritating and not describing the problem correcly, when an argument in sprintf is incorrect (%$1s instead of %1$s).

PHP Xampp installation, not really changed anything, so should be about the default.

Reproduce code:
$string = 'foo %$1s';
var_dump(sprintf($string, 'bar'));

From manual page: function.sprintf#Parameter-Liste

Expected result:
E_WARNING: error while parsing

(or similiar)

Actual result:
Warning: sprintf() [function.sprintf]: Argument number must be greater than zero in


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-10-13 16:54 UTC] chrisstocktonaz at gmail dot com
Here is a small patch for this.

Index: ext/standard/formatted_print.c
--- ext/standard/formatted_print.c      (revision 289616)
+++ ext/standard/formatted_print.c      (working copy)
@@ -449,9 +449,14 @@
                                if (format[temppos] == '$') {
                                        argnum = 
php_sprintf_getnumber(format, &inpos);
-                                       if (argnum <= 0) {
+                                       if ('%' == format[temppos-1]) 
+                                               php_error_docref(NULL 
TSRMLS_CC, E_WARNING, "Parse error, expecting argument specifier 
following '%' at string offset %d", temppos);
+                                               return NULL;
+                                       } else if (argnum <= 0) {
+                                               efree(result);
+                                               efree(args);
TSRMLS_CC, E_WARNING, "Argument number must be greater than zero");
                                                return NULL;
 [2010-12-20 09:16 UTC]
-Package: Feature/Change Request +Package: Strings related
 [2010-12-20 09:16 UTC]
-Operating System: Windows 7 +Operating System: *
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Apr 15 00:01:28 2024 UTC