php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78944 current() function on an empty custom ArrayIterator returns its properties
Submitted: 2019-12-11 10:54 UTC Modified: 2019-12-11 11:03 UTC
From: zoeslam at gmail dot com Assigned:
Status: Not a bug Package: SPL related
PHP Version: 7.4.0 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: zoeslam at gmail dot com
New email:
PHP Version: OS:

 

 [2019-12-11 10:54 UTC] zoeslam at gmail dot com
Description:
------------
Calling current() function on an empty custom ArrayIterator returns its properties.

https://3v4l.org/4MTF2

Bug present from PHP 7.4, prior versions are not affected

Test script:
---------------
class MyArrayIterator extends \ArrayIterator
{
    private $foo = 'bar';
}

$ai = new MyArrayIterator([]);
var_dump(count($ai));
var_dump($ai->current());
var_dump(current($ai));

Expected result:
----------------
int(0)
NULL
bool(false)

Actual result:
--------------
int(0)
NULL
string(3) "bar"

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-12-11 11:03 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2019-12-11 11:03 UTC] requinix@php.net
See bug #77864
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 06:01:34 2025 UTC