Missing format specifier at end of string¶
Description¶
This error is related to the parsing of the format string. In the first example, PHP finds two % characters, and expect each time to be followed by a format character. When the % is at the end of the string, there is no more character to parse, hence the error message.
Also, note the second illustration, which uses a dot . after the %. This is a padding character, so the parser set it aside, and then, look for the format character itself, while reaching the end of the line.
This error applies to printf(), sprintf(), vprintf(), vsprintf().
Example¶
<?php
printf('%s %', 'a', 'b');
printf('%s %.', 'a', 'b');
?>
Solutions¶
Add the missing format character at the end of the line.
Remove the final % char in the format line.
Add another % at the end of the line, to make it a literal % char in the format.
See Also¶
Changed Behavior¶
This error may appear following an evolution in behavior, in previous versions. See ` <https://php-changed-behaviors.readthedocs.io/en/latest/behavior/.html>`_.