Skip to content

Conversation

@dstogov
Copy link
Member

@dstogov dstogov commented Jan 28, 2015

Implementation of https://wiki.php.net/rfc/php7_foreach

  • "foreach by value" don't relay on internal array/object pointer and doesn't perform array duplication. It just locks it incrementing reference counter. If the original array is modified by some code, the copy on write is performed and "foreach" still work with the old copy.
  • it makes no difference if array given to "foreach by value" is reference itself
  • "foreach by reference" still use internal array/object pointer and should work similar to PHP-5 except for few inconsistent cases.

- "foreach by value" don't relay on internal array/object pointer and doesnt perform array duplication. It just locks it incrementing reference counter. If the original array is modified by some code, the copy on write is performed and "foreach" still work with the old copy.

- it makes no difference if array given to "foreach by value" is reference itself

- "foreach by reference" still use internal array/object pointer and should work similar to PHP-5. (This id not completely implemented)
* master:
  fix unportable dereferencing
  fbird_close if connection_id omitted, the last opened link is assumed , so it was already closed
  Fixed #68868 (Segfault in clean_non_persistent_constants() in SugarCRM 6.5.20)
* master:
  reorder the branches
  ppid must be IS_STRING
  Use proper type
  The argument must be not changed in session_start
  Fixed annoying warnings
  Cleanup session id files after test
  Fixed Bug #68941 mod_files.sh is a bash-script
  Remove support for hex number from is_numeric_string
  add imap
  Update News
  Fixed bug #68901 (use after free)
  Remove legacy code
  Forgot to apply important peace of patch
  Fixed crash
  Fixed some annoying warnings
  Fix typo in doc
  Update UPGRADING and UPGRADING.INTERNALS
  Make session_decode return FALSE when it fails. Fix a test. Use proper types.
  WIP - test passes
* master:
  Fixed bug #68945 (Unknown admin values segfault pools)
  Add check for null pointer, as done in case 5 lines above.
  Fixed valgrind issue in mb_ereg_replace_variation1.phpt
  Remove excessive macros
  Use bash rather than sh
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we set nInternalPointer here / why are hash table iterators initialized with nInternalPointer? Wouldn't it be better to make it completely independent?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I got this idea a day before and already have implementation, but I'm not sure if it's a right decision. I generalized API, so to switch to this behavior we would need just remove nInternalPointer assignments in FE_RESET/FE_FETCH. I'll rise a question on @Internals.

@nikic
Copy link
Member

nikic commented Jan 30, 2015

It would be nice to port ArrayIterator/ArrayObject to use HashTableIterator as well - it currently uses checks similar to what was done in foreach.

@dstogov
Copy link
Member Author

dstogov commented Jan 31, 2015

I don't like to do it as a part of this RFC. SPL may be changed later.

On Sat, Jan 31, 2015 at 1:49 AM, Nikita Popov notifications@github.com
wrote:

It would be nice to port ArrayIterator/ArrayObject to use
HashTableIterator as well - it currently uses checks similar to what was
done in foreach.


Reply to this email directly or view it on GitHub
#1034 (comment).

@nikic
Copy link
Member

nikic commented Jan 31, 2015

I'm mainly asking about SPL, because I suspect it may have an impact on the design of HashTableIterator. The problem is that foreach uses an unusual iteration pattern for arrays:

reset();
while (get_current_data(&data) == SUCCESS) {
    move_forward(); // <--
    code(data);
}

While foreach over iterators (and all other iteration code) will have the move_forward() after the code(). The current HashTableIterator implementation is bound to the pattern that foreach uses, e.g. because it advances to the next element on hash_del. If the move_forward happened after the code, we'd have to go to the previous element instead.

My solution to this was to change foreach for arrays to the usual pattern - however this required having an extra "iterator before first position" state for hash positions (like "iterator after last position" is currently INVALID_IDX).

@smalyshev smalyshev added the RFC label Feb 1, 2015
* master: (74 commits)
  Revert "Revert "Fixed warning "(null)(): supplied resource is not a valid cURL handle resource in Unknown on line 0"""
  fix sizeof size
  - Updated to version 2015.1 (2015a)
  - Updated to version 2015.1 (2015a)
  - Updated to version 2015.1 (2015a)
  Fix #66479: Wrong response to FCGI_GET_VALUES
  Fix bug #64938: libxml_disable_entity_loader setting is shared between threads
  Fix for a previous commit. i read it as size_t, notssize_t.
  do_fstat changes
  fix group name handling
  fix TSRM
  add NEWS
  Added test and possible fix for https://bugs.php.net/bug.php?id=67068
  Use better constant since MAXHOSTNAMELEN may mean shorter name
  use right sizeof for memset
  Add mitigation for CVE-2015-0235 (bug #68925)
  Add mitigation for CVE-2015-0235 (bug #68925)
  Add mitigation for CVE-2015-0235 (bug #68925)
  Fixed typo in comment
  Added two missing opcache ini directives (restrict_api and mmap_base)
  ...
* master: (65 commits)
  Add load time return type checking to match user land logic
  Add test function arguments
  fix data type mismatch
  fix unitialized val usage
  follow up fix for headers sent, checking a reference would be always true as well
  remove unused variable
  fix wars about importing of locally defined symbols
  fix data type
  Implemented internal function return types
  Updated NEWS
  Revert "Fixed bug #55407 (Impossible to prototype DateTime::createFromFormat)"
  Removed TSRMLS_D
  5.6.7 now
  5.5.23 now
  Simplify code and add comments
  Move zend_object->guards into additional slot of zend_object->properties_table[]. As result size of objects without __get/__set/__unset/__isset magic methods is reduced.
  Revert "json_decode() should generate a syntax error when given ""."
  Add note aout $HTTP_RAW_POST_DATA
  Use object pointers instead of handles
  make buildconf work as expected; autoconf really needs some help with all those external m4s
  ...
* master: (74 commits)
  Shut up, my lovely compiler; I do not like your warnings
  Márcio Almada 	remove dead tokens: T_CHARACTER, T_BAD_CHARACTER.
  fix detection of mbstate_t with clang
  Add missing NEWS and UPGRADING for bug #68938
  moved the part of the test into an appropriate place
  Removed unused REGISTER_PDO_CONST_LONG
  Fix another invalid free of CG(interned_empty_string)
  add tests for #68996
  Fixed #68790 (Missing return)
  Fixed #68790 (Missing return)
  Update README.TESTING
  Small Spacing adjustments for better reading
  added ODBCVER to phpinfo()
  added PCRE JIT availability info to phpinfo()
  Improve tests for bug 67436
  Fixed issue php#1041 (Fix build in OSX with --enable-dtrace)
  fix setting default ODBCVER value in config.w32
  updated NEWS
  updated NEWS
  Fixed bug #68964 Allowed memory size exhausted with odbc_exec
  ...
* master: (61 commits)
  Fixed bug #69025 (Invalid read of size 4 when calling __callStatic)
  add missing test for class member access with deference relates to https://wiki.php.net/rfc/uniform_variable_syntax
  fix dir separator in test
  fix incompatible pointer type
  fix values for gid and uid
  silence unused variable warning
  remove useless condition
  fix uninitialized value warn
  Forget this change
  Expose zend_string_equals_str_ci
  Fixed possible memory leak
  Add a constant of type CONST_PERSISTENT to test
  Revert removal of two ReflectionParameter functions Rather fix them for now by exempting function parameter defaults from *any* (non-ct) constant substitution (also from persistent constant substitution, which was already broken before)
  Don't convert options in-place. They may be elements of constant array.
  fix dir separator in test
  better alignment + support size_t
  Revert "Revert "Improve and generalize class constant substitution""
  Add missing header inclusion
  Get rid of old HashTable iteration API
  Update libmagic.patch to reflect changes made
  ...
* master:
  Pass maxlifetime to save handlers
  Added test for #69017
  Fixed bug #69017 (Fail to push to the empty array with the constant value defined in class scope)
  Align format to Fixed bug #... , later used to create the website changelog
  Add missing NEWS entry for revert of bug #41631
  Add CVE ID to bug #68676
  Align email format for recent NEWS entries
  Bug #55508 was fixed in 5.5.19 with 15ba757, not in 5.5.18
  Add missing NEWS entry for revert of bug #41631
  Add missing NEWS entry for bug #68027
  Align format for bug #68799
  Bug #68361 was fixed in 5.5.20 using 327d4f9, not in 5.5.19
  Bug #55618 was fixed in 5.5.21 using eaf107c
  Add security bugs fixed in 5.5.18
  Add CVE ID to bug #68676
  Align email format for recent NEWS entries
@dstogov
Copy link
Member Author

dstogov commented Feb 12, 2015

Merged into master

@dstogov dstogov closed this Feb 12, 2015
@dstogov dstogov deleted the foreach branch October 14, 2019 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants