php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69758 Item added to array not being removed by array_pop/shift
Submitted: 2015-06-05 00:11 UTC Modified: -
From: gsherwood at squiz dot net Assigned:
Status: Closed Package: *General Issues
PHP Version: master-Git-2015-06-04 (Git) OS: NA
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: gsherwood at squiz dot net
New email:
PHP Version: OS:

 

 [2015-06-05 00:11 UTC] gsherwood at squiz dot net
Description:
------------
My unit tests began failing on PHP7 builds about a month ago, which I tracked down to an array_pop() call not actually removing the element from the array. This works fine on earlier PHP7 builds and all PHP5 versions, so I'm reporting it as a BC break, and a possible bug report.

I have a test case with output for various versions here: http://3v4l.org/mR874

PHP version information below:

$ php --version
PHP 7.0.0-dev (cli) (built: Jun  5 2015 08:25:20)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0-dev, Copyright (c) 1998-2015 Zend Technologies



Test script:
---------------
<?php
$tokens     = array();
$conditions = array();
for ($i = 0; $i <= 10; $i++) {
    $tokens[$i] = $conditions;

    // First integer must be less than 8
    // and second must be 8, 9 or 10
    if ($i !== 0 && $i !== 8) {
        continue;
    }

    // Add condition and then pop off straight away.
    // Can also use array_shift() here.
    $conditions[$i] = true;
    $oldCondition   = array_pop($conditions);
}

// Conditions should be empty.
print_r($conditions);

Expected result:
----------------
Array
(
)

Actual result:
--------------
Array
(
    [8] => 1
)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-06-05 03:57 UTC] laruence@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=497f9f2cda4e2f2281cfbde148e7408908261c63
Log: Fixed bug #69758 (Item added to array not being removed by array_pop/shift)
 [2015-06-05 03:57 UTC] laruence@php.net
-Status: Open +Status: Closed
 [2016-07-20 11:38 UTC] davey@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=497f9f2cda4e2f2281cfbde148e7408908261c63
Log: Fixed bug #69758 (Item added to array not being removed by array_pop/shift)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 17:01:29 2024 UTC