php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #77451 %g format for printf & sprintf is misdocumented
Submitted: 2019-01-12 18:26 UTC Modified: 2019-03-24 17:46 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: markamery at btinternet dot com Assigned: girgias (profile)
Status: Closed Package: Strings related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2019-01-12 18:26 UTC] markamery at btinternet dot com
Description:
------------
At http://php.net/manual/en/function.sprintf.php, the %g specifier is documented as follows:

    shorter of %e and %f.

This isn't true. %g often uses scientific notation even though it'd be shorter not to, and what's more, its output may differ from BOTH %e and %f, since it strips trailing zeros and %f and %e don't.

See https://stackoverflow.com/q/54162152/1709587 where I explore this point at length.


Patches

sprintf_related_functions_improvement (last revision 2019-03-20 17:50 UTC by girgias@php.net)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-01-14 04:44 UTC] girgias@php.net
-Summary: %g specifier to printf is misdocumented +Summary: %g format for printf & sprintf is misdocumented -Status: Open +Status: Verified -Package: Documentation problem +Package: Strings related -Operating System: N/A +Operating System:
 [2019-01-14 04:44 UTC] girgias@php.net
Thanks for noticing this, you can also submit a patch to fix the documentation by using the online editor located at https://edit.php.net
 [2019-02-12 20:43 UTC] girgias@php.net
-Assigned To: +Assigned To: girgias
 [2019-02-12 23:15 UTC] girgias@php.net
-Assigned To: girgias +Assigned To: cmb
 [2019-02-12 23:15 UTC] girgias@php.net
Wrote a patch to improve the sprintf doc:
http://edit.php.net/?patchID=3291&project=PHP

@cmb I was thinking to maybe move the examples out of the format parameter
and then move the format parameter XML into an entity and include this entity in all the other related functions (such as printf or fscanf for example).

Oh also I couldn't try it out as I haven't managed to download the Doc Block Rendering system onto my Linux Sub System so not totally sure how this patch looks like.
 [2019-02-26 17:33 UTC] girgias@php.net
Updated the patch [1] to move the format parameter into an XML Snippet and added it to all relevant functions.
It validates and the doc looks good to me.

Can you have a look and/or merge it @cmb?

[1] https://edit.php.net/?patchID=3291&project=PHP
 [2019-03-03 14:35 UTC] cmb@php.net
-Assigned To: cmb +Assigned To:
 [2019-03-20 17:50 UTC] girgias@php.net
The following patch has been added/updated:

Patch Name: sprintf_related_functions_improvement
Revision:   1553104231
URL:        https://bugs.php.net/patch-display.php?bug=77451&patch=sprintf_related_functions_improvement&revision=1553104231
 [2019-03-20 17:54 UTC] girgias@php.net
-Assigned To: +Assigned To: girgias
 [2019-03-24 16:30 UTC] girgias@php.net
Automatic comment from SVN on behalf of girgias
Revision: http://svn.php.net/viewvc/?view=revision&revision=347041
Log: Improve sprintf documentation and related functions (such as printf)
Fix Doc Bug #77451
Integrate Note 111201 into doc http://php.net/manual/en/function.sprintf.php#111201
 [2019-03-24 17:46 UTC] girgias@php.net
-Status: Verified +Status: Closed
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun Aug 25 19:01:26 2019 UTC