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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

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-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 10:01:28 2024 UTC