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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2022 The PHP Group
All rights reserved.
Last updated: Fri May 20 13:05:46 2022 UTC