php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #81427 ArrayObject no longer supports end() etc.
Submitted: 2021-09-09 14:50 UTC Modified: 2021-09-09 17:04 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:1 of 2 (50.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: brian at deshong dot net Assigned:
Status: Verified Package: SPL related
PHP Version: 7.4.23 OS: Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: brian at deshong dot net
New email:
PHP Version: OS:

 

 [2021-09-09 14:50 UTC] brian at deshong dot net
Description:
------------
We've seen a variation in the behavior of end() when calling it on an ArrayObject between 7.3.26 and 7.4.23.

The test script returns the final element in the ArrayObject on PHP 7.3.26, but false on PHP 7.4.23.

I'm unclear as to why this behavior has changed as there are no documented changes to end() or ArrayObject behavior that I see in the PHP 7.3 to 7.4 migration guide.

Test script:
---------------
<?php                                                                                                                   
$arrayObject = new ArrayObject();                                                                                       
$arrayObject->append(new stdClass());                                                                                   
$arrayObject->append(new stdClass());                                                                                   
                                                                                                                        
var_dump(end($arrayObject)); 

Expected result:
----------------
I expect to have the final ArrayObject element returned by the call to end() on both PHP 7.3.x and 7.4.x.

Actual result:
--------------
On PHP 7.3.26, the final object within the ArrayObject is returned.

On PHP 7.4.23, false is returned.

7.3.26
------

$ php -v
PHP 7.3.26 (cli) (built: Mar 29 2021 18:09:35) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.26, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.26, Copyright (c) 1999-2018, by Zend Technologies
    with Xdebug v2.9.6, Copyright (c) 2002-2020, by Derick Rethans

$ php ./test.php 
test.php:6:
class stdClass#3 (0) {
}


7.4.23
------

$ php -v
PHP 7.4.23 (cli) (built: Aug 31 2021 16:08:26) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.23, Copyright (c), by Zend Technologies
    with Xdebug v3.0.3, Copyright (c) 2002-2021, by Derick Rethans

$ php ./test.php
test.php:6:
bool(false)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-09-09 16:39 UTC] cmb@php.net
This behavioral change has been introduced by commit
a5fa51afbb[1]; I'm not sure whether this was intended.

[1] <https://github.com/php/php-src/commit/a5fa51afbbd87bedeb1c5fd7c9a6cf3c971ab14c>
 [2021-09-09 17:04 UTC] cmb@php.net
-Summary: Different behavior calling end() on an ArrayObject between 7.3.26 and 7.4.23 +Summary: ArrayObject no longer supports end() etc. -Status: Open +Status: Verified -Type: Bug +Type: Documentation Problem
 [2021-09-09 17:04 UTC] cmb@php.net
Ah, as of PHP 7.4.0, ArrayObject no longer supports end()[1],
etc.[2]  This is actually documented in the migration guide[3], but
may also need to be documented in the manual proper.  Furthermore,
the documentation of end(), etc., could be improved (it says
returns false for empty array).

[1] <https://3v4l.org/0F845>
[2] <https://3v4l.org/7sonB>
[3] <https://www.php.net/manual/en/migration74.incompatible.php#migration74.incompatible.spl>
 [2023-04-25 08:19 UTC] preetishaub at gmail dot com
Travel Adventure Blog are sharing latest news about travel, desert safari, destination, tourist spot, adventure travel, hotel, resturants etc. More info to visit:(https://traveladventureblog.com)github.com
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC