![]() To make this work each dummy object has to store a key (which can freely be duplicated without problems) that it passes to the global object when rewind, key, current, next, and valid were called on the dummy object. Being that I had many dummy objects representing different data sets I chose to store each data set as a subarray contained within the global object. The solution is instead to iterate over the keys of $a.Īnd using $a (or creating an alias of $a as $d and dealing with the consequences of using aliases).įor the curious, I was implementing the Iterator interface on a dummy object and calling a global object to do the actual iteration (also to cope with PHP's lack of C-style pointers which when doing a $a = $b on objects would cause the data in $a to be inconsistent with the data in $b when modified). Clearly the internal pointer of $a was reset by doing the foreach loop over $a.Įach time the foreach loop iterated over the 'a' and 'b' keys of $a it made a copy of $a and $a into $d which resetted the internal pointers of $a and $a despite making no obvious changes. ![]() The result of the two var dumps are 3 and 0, respectively. Set the pointer of $a to 'b' and the pointer of 'b' to 'CC' The following code demonstrates the resetting of a subarray: The problem was in doing a foreach() on the parent array PHP was making a copy of the subarrays and in doing so it was resetting the internal pointers of the original array. I had a problem with PHP 5.0.5 somehow resetting a sub-array of an array with no apparent reason. If your array has more dimensions, it won't probably cause a fatal error but you will get different results when you combine reset() and key() or use them consecutively. While in the second method you just reset the array and didn't use a returning value instead you reset the pointer and than extracted the first key of an array. ![]() This is perfectly normal because in the first method, reset() returned the first "value" of the 'biscuits' element which is to be "cbosi". 'chocolates' => array( 'coco1' => 'cococ', 'coco2' => 'prococ' ),Įcho key ( reset ( $products )) // Fatal errorĮcho key ( $products ) // Will print 'biscuit1' ![]() Since reset() returns the first "value" of the array beside resetting its internal pointer it will return different results when it is combined with key() or used separately. Getting Started Introduction A simple tutorial Language Reference Basic syntax Types Variables Constants Expressions Operators Control Structures Functions Classes and Objects Namespaces Enumerations Errors Exceptions Fibers Generators Attributes References Explained Predefined Variables Predefined Exceptions Predefined Interfaces and Classes Predefined Attributes Context options and parameters Supported Protocols and Wrappers Security Introduction General considerations Installed as CGI binary Installed as an Apache module Session Security Filesystem Security Database Security Error Reporting User Submitted Data Hiding PHP Keeping Current Features HTTP authentication with PHP Cookies Sessions Dealing with XForms Handling file uploads Using remote files Connection handling Persistent Database Connections Command line usage Garbage Collection DTrace Dynamic Tracing Function Reference Affecting PHP's Behaviour Audio Formats Manipulation Authentication Services Command Line Specific Extensions Compression and Archive Extensions Cryptography Extensions Database Extensions Date and Time Related Extensions File System Related Extensions Human Language and Character Encoding Support Image Processing and Generation Mail Related Extensions Mathematical Extensions Non-Text MIME Output Process Control Extensions Other Basic Extensions Other Services Search Engine Extensions Server Specific Extensions Session Extensions Text Processing Variable and Type Related Extensions Web Services Windows Only Extensions XML Manipulation GUI Extensions Keyboard Shortcuts ? This help j Next menu item k Previous menu item g p Previous man page g n Next man page G Scroll to bottom g g Scroll to top g h Goto homepage g s Goto search ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |