php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67782 Internal Cursors
Submitted: 2014-08-05 17:11 UTC Modified: 2015-06-30 17:02 UTC
From: joelm@php.net Assigned:
Status: Open Package: PHP Language Specification
PHP Version: PHP-5.6 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: joelm@php.net
New email:
PHP Version: OS:

 

 [2014-08-05 17:11 UTC] joelm@php.net
Description:
------------
https://github.com/php/php-langspec/blob/master/spec/12-arrays.md#arrays

 The concept of an array's internal cursor or an object's internal cursor is never mentioned. The state of the internal cursor of an array or object can be witnessed via the current(), key(), next(), prev(), reset(), end(), and each() library functions. While it's technically library functions that expose the state of the cursor to the programmer, you can find code deep in the core array/object implementation of PHP5 that deals with and maintains internal cursors. Also, internal cursors get mentioned in various parts of the php.net documentation, including the documentation for "foreach", so internal cursors are arguably a language feature. 


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-06-28 21:55 UTC] stas@php.net
-PHP Version: Irrelevant +PHP Version: PHP-5.6
 [2015-06-28 21:55 UTC] stas@php.net
I'm not sure this has a place in the spec, as this is largely an implementation detail, also one that changes somewhat between 5.6 and 7.
 [2015-06-30 17:02 UTC] fredemmott@php.net
In case this does get documented: one weird case is that these also work with some container objects, but not subclasses of them - eg if you override offsetGet in an ArrayObject subclass, you get different results with cur/next/prev vs other forms of iteration.

For what it's worth, HHVM hasn't implemented these for objects and we've had very few compatibility issues reported because of this; almost all of the reports actually turned out to be buggy PHP code because of the subtleties of it.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Sep 24 21:03:36 2021 UTC