Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

illegal usage of array_walk in ObjectProperty, ClassMapAutoloader #4296

Closed
wants to merge 2 commits into from

Conversation

weierophinney
Copy link
Member

Per definition of array_walk: http://php.net/manual/en/function.array-walk.php it's not allowed to change the referenced array in the process of array_walk.

e.g. on extraction ObjectProperty does not correctly apply filters. http://pastie.org/7684226

@weierophinney
Copy link
Member

The definition doesn't say anything about not altering the array; it mentions only that changes to the array will not affect the internal pointer of array_walk. As such, modifying it should be fine in most cases.

The one case it looks to be problematic is the ObjectProperty hydrator; I'm going to break that into two operations: array_filter and then array_walk.

- array_walk() will traverse every pointer in the original input,
  regardless of modifications to the input, leading to errors. Modified
  ObjectProperty hydrator to filter keys first, and then extract values.
@weierophinney
Copy link
Member

array_filter would not work as it's not aware of keys (though it preserves them); I instead did a foreach over the array_keys, and removed elements that way, and then ran array_walk. All tests are passing now, based on the test case that I derived from your paste, @NuffSaid .

- array_keys() essentially creates a new array, using more memory. It's also
  like iterating the array twice.
- If we're going to iterate once, might as well only do it once.
@akrabat
Copy link
Contributor

akrabat commented Apr 25, 2013

Fails to merge cleanly to develop...

* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Stdlib
Copy link
Contributor

Choose a reason for hiding this comment

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

remove @Package

@weierophinney
Copy link
Member

Fails to merge cleanly to develop...

That's not unusual; there are a fair number of changes on develop (try merging any view helper changes... (-: ). Should be fairly straightforward to resolve the differences.

@akrabat akrabat closed this in 20525b9 Apr 26, 2013
akrabat added a commit that referenced this pull request Apr 26, 2013
weierophinney added a commit to zendframework/zend-stdlib that referenced this pull request May 15, 2015
- array_walk() will traverse every pointer in the original input,
  regardless of modifications to the input, leading to errors. Modified
  ObjectProperty hydrator to filter keys first, and then extract values.
gianarb pushed a commit to zendframework/zend-stdlib that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-stdlib that referenced this pull request May 15, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants