php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69299 Regression in array_filter's $flag argument in PHP 7
Submitted: 2015-03-25 14:41 UTC Modified: -
From: weierophinney@php.net Assigned:
Status: Closed Package: Arrays related
PHP Version: master-Git-2015-03-25 (Git) OS: Linux
Private report: No CVE-ID: None
 [2015-03-25 14:41 UTC] weierophinney@php.net
Description:
------------
PHP 5.6.0 added a third argument to array_filter, $flag, which can accept one of the integer constants ARRAY_FILTER_USE_KEY or ARRAY_FILTER_USE_BOTH. When the former is specified, the key is passed as the sole argument to the callback; when the latter is specified, the value and the key, in that order, are passed to the callback.

Under the current master branch, the $flag is ignored.

Test script:
---------------
$toFilter = array('foo' => 'bar', 'fiz' => 'buz');
$filtered = array_filter($toFilter, function ($value, $key) {
    if ($value === 'buz'
        || $key === 'foo'
    ) {
        return false;
    }
    return true;
}, ARRAY_FILTER_USER_BOTH);
var_export($filtered);

Expected result:
----------------
array()

Actual result:
--------------
Missing argument 2 for {closure}()

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-03-25 15:51 UTC] laruence@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=d55d10c7fd7353bfc9e42e3d81bd61a87c063770
Log: Fixed bug #69299 (Regression in array_filter's $flag argument in PHP 7)
 [2015-03-25 15:51 UTC] laruence@php.net
-Status: Open +Status: Closed
 [2016-07-20 11:39 UTC] davey@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=d55d10c7fd7353bfc9e42e3d81bd61a87c063770
Log: Fixed bug #69299 (Regression in array_filter's $flag argument in PHP 7)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC