php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #20394 prev(), next(), current(), end() should say 'value' rather than 'element'
Submitted: 2002-11-12 10:31 UTC Modified: 2004-03-26 18:06 UTC
From: phpbugs at priorwebsites dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.3.0-pre2 OS:
Private report: No CVE-ID: None
 [2002-11-12 10:31 UTC] phpbugs at priorwebsites dot com
In the array documentation for current(), prev(), next(), end(), it should use the word 'value' wherever it means the value in the key=>value pair, and not the word element.

I was struggling to understand what the array functions prev() and next() return, as I rarely use them, since each() normally does what is needed.  I understand well when the array documentation talks about 'key' and 'value', but here was a seemingly new concept to me, 'element'.  At one stage I thought it must return the same as each(), i.e. the $key=>$value pair, though comparing the datatypes returned disproved this theory.  Finally, I deduced from the documentation for current() which talks about when the value is 0 or "", that what is returned is what is normally referred to in the array documentation as 'value'.

It should not require such detective work!!

Maybe an example in, say, prev(), would make it all clear:

$transport = {'foot', 'bike', 'car', 'plane'}
$mode = current($transport);  // $mode = 'foot';
$mode = next($transport);     // $mode = 'bike';
$mode = next($transport);     // $mode = 'car';
$mode = prev($transport);     // $mode = 'bike' again
$mode = end($transport);      // $mode = 'plane'


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-07-18 03:40 UTC] philip@php.net
The docs seem wrong, or at least I don't understand them.  For example, when it says if the element is 0 or "", current() will return boolean false ...  In testing, if either the value or key equals 0, it returns 0, not false.  Maybe it's referring to == vs === type checking?  Or behavior has changed?  Either way, rewording is required.

I've updated the docs for prev/next/current/end to reflect the following view:

  element = key/value pair
  value   = array value (i.e. array('key' => 'value'))

And added your example to all but end()'s docs.  Am leaving this report open until someone clears up the 'if element equal 0 or "", this returns boolean false' issue.


 [2004-03-26 18:06 UTC] amt@php.net
They don't return false, but they return values that 
evaluate to false inside of an if() or a while().
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 20 13:01:34 2024 UTC