Skip to content

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

Closed
reeze wants to merge 1 commit into
php:PHP-5.3from
reeze:fix-array-object-notice
Closed

reeze wants to merge 1 commit into
php:PHP-5.3from
reeze:fix-array-object-notice

Conversation

@reeze

@reeze reeze commented Apr 5, 2012

Copy link
Copy Markdown
Contributor

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.

Comment thread ext/spl/spl_array.c Outdated

Copy link
Copy Markdown
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

reeze commented Apr 20, 2012

Copy link
Copy Markdown
Contributor Author

update: error messsage updated & if else branch cleanup

@reeze

reeze commented May 2, 2012

Copy link
Copy Markdown
Contributor Author

Thanks for reply, I will updated it soon;)

@dsp

dsp commented May 2, 2012

Copy link
Copy Markdown
Member

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
Copy Markdown
Contributor

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

@smalyshev

Copy link
Copy Markdown
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

reeze commented May 2, 2012

Copy link
Copy Markdown
Contributor Author

sorry ,my fault it's Bug#61527

@dsp

dsp commented May 2, 2012

Copy link
Copy Markdown
Member

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

reeze commented May 2, 2012

Copy link
Copy Markdown
Contributor Author

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

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

@reeze

reeze commented May 2, 2012

Copy link
Copy Markdown
Contributor Author

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

reeze commented May 2, 2012

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
Contributor

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

@laruence

laruence commented May 3, 2012

Copy link
Copy Markdown
Member

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

@reeze

reeze commented May 3, 2012

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown

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