php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79390 reset(new \ArrayObject()) return (bool) false in php7.4
Submitted: 2020-03-18 07:04 UTC Modified: 2020-03-18 07:28 UTC
From: zhongyunchang at yeah dot net Assigned: sjon (profile)
Status: Closed Package: Arrays related
PHP Version: 7.4.3 OS: Any
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: zhongyunchang at yeah dot net
New email:
PHP Version: OS:

 

 [2020-03-18 07:04 UTC] zhongyunchang at yeah dot net
Description:
------------
---
From manual page: https://php.net/migration74
---

<?php
$arrayObject = new \ArrayObject();
$arrayObject->append('test string');
echo reset($arrayObject);

I geted "test string" in <=PHP7.3 but (bool) false in PHP7.4.x, not found any explain on official document.

Test script:
---------------
<?php
$arrayObject = new \ArrayObject();
$arrayObject->append('test string');
echo reset($arrayObject);

Expected result:
----------------
 "test string"

Actual result:
--------------
bool "false"

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-03-18 07:28 UTC] sjon@php.net
-Status: Open +Status: Closed -Type: Feature/Change Request +Type: Bug -Package: *General Issues +Package: Arrays related -Assigned To: +Assigned To: sjon
 [2020-03-18 07:28 UTC] sjon@php.net
The change is documented here: https://www.php.net/manual/en/migration74.incompatible.php

>  Calling get_object_vars() on an ArrayObject instance will now always return the properties of the ArrayObject itself (or a subclass). Previously it returned the values of the wrapped array/object unless the ArrayObject::STD_PROP_LIST flag was specified.
> Other affected operations are:
>
>    reset(), current(), etc. Use Iterator methods instead. 

Although a bit more cumbersome, appending this will help you:

$i = $arrayObject->getIterator();
$i->rewind();
var_dump($i->current());
 [2020-03-18 08:58 UTC] zhongyunchang at yeah dot net
Thank you for your help, I got it.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 20:01:36 2025 UTC