#49802 [Com]: Irritating error message when passing irregular arguments for parsing (sprintf)

From: Date: Tue, 13 Oct 2009 16:54:17 +0000
Subject: #49802 [Com]: Irritating error message when passing irregular arguments for parsing (sprintf)
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-2937@lists.php.net to get a copy of this message
ID: 49802 Comment by: chrisstocktonaz at gmail dot com Reported By: timm dot forallthestuff at web dot de Status: Open Bug Type: Documentation problem Operating System: Windows 7 PHP Version: 5.3.0 New Comment: 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]) { efree(result); efree(args); + 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); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument number must be greater than zero"); return NULL; }c Previous Comments: ------------------------------------------------------------------------ [2009-10-07 12:45:52] timm dot forallthestuff at web dot de Description: ------------ 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 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=49802&edit=1

« previous php.doc.bugs (#2937) next »