Doc #61596 [Opn->Csd]: Documentation doesn't mention negative return values

From: Date: Mon, 02 Apr 2012 06:52:57 +0000
Subject: Doc #61596 [Opn->Csd]: Documentation doesn't mention negative return values
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-8155@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=61596&edit=1 ID: 61596 Updated by: aharvey@php.net Reported by: rosuav at rosuav dot com Summary: Documentation doesn't mention negative return values -Status: Open +Status: Closed Type: Documentation Problem Package: Documentation problem Operating System: Linux [Debian 6.0.4] PHP Version: 5.4Git-2012-04-02 (Git) -Assigned To: +Assigned To: aharvey Block user comment: N Private report: N New Comment: This bug has been fixed in the documentation's XML sources. Since the online and downloadable versions of the documentation need some time to get updated, we would like to ask you to be a bit patient. Thank you for the report, and for helping us make our documentation better. Previous Comments: ------------------------------------------------------------------------ [2012-04-02 06:52:53] aharvey@php.net Automatic comment from SVN on behalf of aharvey Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=324696 Log: Fix doc bug #61596 (Documentation doesn't mention negative return values). ------------------------------------------------------------------------ [2012-04-02 03:00:36] rosuav at rosuav dot com Description: ------------ Originally tested with PHP 5.3.3.7+squeeze8 with Suhosin-Patch (cli) (built: Feb 10 2012 13:05:56) from Debian repository, confirmed with latest from Debian's git repository (announced as 5.4.0). The sscanf() function, when given variables into which to put its results, is documented as returning the number of assigned values: http://php.net/manual/en/function.sscanf.php Usage, however, shows that it can return -1 if the input string does not match the pattern - see test script. I'm not sure if this is a documentation error or an actual function bug (it seems odd that a prefix match should affect the return value), but either way, the disconnect is confusing. The issue seems to arise from ext/standard/scanf.c lines 687-695 (in latest cloned from git), in which different treatment is given to mismatch and underflow, and then line 1200 triggers the -1 return in the case of underflow. My original code (very similar to the test script attached) was using "if (sscanf(....)) do_stuff" - had I known about negative returns, a more correct line of code would say "if (sscanf(...)>0) do_stuff" instead. Test script: --------------- <?php $_POST = array('foobar1'=>5, 'foobar2'=>7, 'foo'=>'Do some Fooage', 'other'=>42); foreach ($_POST as $k=>$v) { $ret=sscanf($k,'foobar%d',$id); echo "key $k -> id $id, value $v - sscanf returned $ret\n"; } Expected result: ---------------- According to the documentation, the foobar1 and foobar2 lines should have a return value of 1, because $id was assigned to; the other two should have a return value of 0. Actual result: -------------- The foo line has a return value of -1, unexpected according to the documentation. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=61596&edit=1

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