|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77864 ArrayObject->getIterator not working in PHP 7.4 snapshot?
Submitted: 2019-04-08 17:32 UTC Modified: 2019-04-08 17:58 UTC
From: jay at diablomedia dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: master-Git-2019-04-08 (snap) OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
7 + 5 = ?
Subscribe to this entry?

 [2019-04-08 17:32 UTC] jay at diablomedia dot com
I first noticed this in this test suite on travis running on the php7.4-snapshot that's available on Travis (I believe this is a nightly snapshot of the 7.4 branch):

There are two tests that fail there due to `get_class` trying to operate on a boolean rather than on a class (these tests pass fine in all versions prior to 7.4).

Looking at the code a bit, I've been able to narrow the failure down to a simple script that I've added to the "Test script" section of this bug (also on

In all versions prior to PHP 7.4, this will output `int(1)` in PHP 7.4 it outputs `bool(false)`.

Here's output from `php --version` in the docker container I was testing this on locally:

docker run -it --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp tommymuehle/docker-alpine-php-nightly php --version
PHP 8.0.0-dev (cli) (built: Feb 11 2019 05:57:53) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies

(seems that container is on the php 8.0 branch (dev-master I assume), but based on the travis failures I'm fairly certain the same issue exists on the current php 7.4 snapshot as well)

Test script:

$array = [1,2,3];

$iterator = (new ArrayObject($array))->getIterator();


Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-04-08 17:56 UTC]
-Summary: ArrayObject->getIterator not working in PHP 7.4 snapshot? +Summary: current(ArrayIterator) not working in PHP 7.4 snapshot -Status: Open +Status: Verified
 [2019-04-08 17:56 UTC]
Yes, master is 8.0 while 7.4 is a branch, done so that some planned 8.0-only changes can start going in without affecting 7.4.

I believe it's currently undefined behavior to use current/key on an iterator that has not been reset yet, so the code should be doing that first.
  $iterator = $this->stack->getIterator();
But that does not fix the problem - at least as far as the test script is concerned.

Looks like it's not just current() but all the others too. Surely all the same single underlying bug. Calling them directly like $iterator->current() does work.
 [2019-04-08 17:58 UTC]
-Summary: current(ArrayIterator) not working in PHP 7.4 snapshot +Summary: ArrayObject->getIterator not working in PHP 7.4 snapshot? -Status: Verified +Status: Not a bug
 [2019-04-08 17:58 UTC]
current() and friends do **not** work on Iterators, they work on arrays and the internal array pointer. When applied to objects current() etc iterate over the properties of the object.

Prior to PHP 7.4 current() etc did work on ArrayIterator specifically (but no other Iterators) due to an implementation quirk, but this is no longer supported.

This change is documented in the upgrading guide at The portable solution is to replace current($iterator) with $iterator->current().
 [2019-04-08 18:40 UTC] jay at diablomedia dot com
Thanks for the update and the explanation of the change.  Will update code where necessary.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sun May 22 02:05:45 2022 UTC