Skip to content

Function: sprintf, misleading documentation #2447

Open
@just-ad-gr

Description

@just-ad-gr

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 :)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions