Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug #61527 (Recursive/ArrayIterator gives misleading notice when array empty or moved to the end) #38

Closed
wants to merge 1 commit into from

Conversation

reeze
Copy link
Contributor

@reeze reeze commented Apr 5, 2012

Hi,

when calling
- ArrayIterator->next(),
- ArrayIterator->key(),
- ArrayIterator->current(),
- RecurseArrayIterator->getChildren()
- RecurseArrayIterator->hasChildren()
it will raise misleading(array was modified outside) message. when array was empty or moved to then end of array.

This pull request is trying to fix it.

Thanks.

@@ -58,6 +58,29 @@
#define SPL_ARRAY_INT_MASK 0xFFFF0000
#define SPL_ARRAY_CLONE_MASK 0x0300FFFF

#define SPL_ARRAY_CHECK_POS_EMPTY_OR_END_REACHED(object, ht, err_msg) do { \
if (!aht) { \
Copy link
Member

Choose a reason for hiding this comment

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

This probably should be ht, as that's what you're passing into the macro.

@reeze
Copy link
Contributor Author

reeze commented Apr 20, 2012

update: error messsage updated & if else branch cleanup

@reeze
Copy link
Contributor Author

reeze commented May 2, 2012

Thanks for reply, I will updated it soon;)

@dsp
Copy link
Member

dsp commented May 2, 2012

btw are you sure the bug id is correct? The bug you refer to is closed and has little to do with your change.

@smalyshev
Copy link
Contributor

Which bug you are trying to fix? Bug #61347 is "inconsistent isset behavior of Arrayobject" and already fixed.

@smalyshev
Copy link
Contributor

There should be no messages when array is iterated to an end - it is perfectly normal thing to do. Empty array is a perfectly normal thing too, there should be no messages on that either. Also, I don't see why array should be rewinded. If it's at the end, it should just stay there.

@reeze
Copy link
Contributor Author

reeze commented May 2, 2012

sorry ,my fault it's Bug#61527

@dsp
Copy link
Member

dsp commented May 2, 2012

I agree with @smalyshev here. It's perfectly valid to iterate over an empty array. As #61527 points out, there shouldn't be any Notice at all in those cases.

@reeze
Copy link
Contributor Author

reeze commented May 2, 2012

em, it makes sense, next() didn't notice too.

so no notice at all in this case, am I right?

@reeze
Copy link
Contributor Author

reeze commented May 2, 2012

but the method related to current entry still need notice if array was empty or reached the end.
so only next() shouldn't complain. I will fix it soon.

thanks

@reeze
Copy link
Contributor Author

reeze commented May 2, 2012

I have updated the patch:

  • No notice anymore when $iter->next() and update the notice message.

@smalyshev I've already rebased the pull request, that has been updated. the previous code show up in discussion.
please refer to the diff.

"There should be no messages when array is iterated to an end - it is perfectly normal thing to do. Empty array is a perfectly normal thing too, there should be no messages on that either. Also, I don't see why array should be rewinded. If it's at the end, it should just stay there."

Thanks.

@smalyshev
Copy link
Contributor

current() should not give any notices either. It should just return false. That notice does not contribute anything.

@laruence
Copy link
Member

laruence commented May 3, 2012

actually, I think only notice for :"modified outside" is enough. no need yelling for "reached the end"

@reeze
Copy link
Contributor Author

reeze commented May 3, 2012

Hi,
I've updated the patch. no extra notice on next(), current() or key(), only notice when array was really modified.
and I refactor some code to reduce duplication. This bug also affect RecuseArrayIterator, I fixed it both of them.

Thanks.

@php-pulls
Copy link

Comment on behalf of stas at php.net:

merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants