Function: sprintf, misleading documentation
Nobody has claimed this yet.
- Dominant language
- XML
- Stars
- 596
- Forks
- 890
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 55
Description
Page: https://www.php.net/manual/en/function.sprintf.php
The confusion is created by the fact that nowhere is stated that sprintf format can accept mulitple flags, even if they are mutually exclusive, like '(char) and 0 or space ( ).
The confusion is brought to light, and actually forced on us, by the specific example:
Example #2 Specifying padding character
<?php
echo sprintf("%'.9d\n", 123);
echo sprintf("%'.09d\n", 123);
?>
I guess you know * , this code sprintf("%'.09d\n", 123); uses two flags, flag '. and flag 0.
Since they can not both be printed, only the last one is used.
But when we read this, and it's not explained, it's very easy like me to lose 40' of your day only to understand what is going on.
So, please fix it, like for example here:
Example #2 Specifying padding character
<?php
echo sprintf("%'.9d\n", 123);
echo sprintf("%'.09d\n", 123); → /* Use of multiple exclusive flags '. and 0 result only the last one to be used */ ←
?>
and after the Flag | Description,
Warning
The flags '(char), (space), 0, are mutually exclusive. If many of them are used on the same format, the last one is applied.
Finally, than you all, for this great tool, PHP! It has allowed many to do great things. Sometimes though I pick my hair out of despair that we are year 2023, PHP8, and PHP is still struggling with things like this XD
Thank you,
have a good day :)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Open the sprintf manual page and inspect Example #2, the flag descriptions, and the surrounding format-string guidance. Update the documentation to explain multiple mutually exclusive padding flags and clarify which flag is applied when they appear together, then verify the example and warning read consistently.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 1/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100