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
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:
MUST BE VALID
Solve the problem:
32 + 40 = ?
Subscribe to this entry?

 
 [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: Wed Apr 24 08:01:29 2024 UTC