php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #75546 Clarification for how iterator_apply's $args are passed to the $function
Submitted: 2017-11-21 06:21 UTC Modified: 2017-11-22 06:31 UTC
From: ycgambo at outlook dot com Assigned:
Status: Verified Package: SPL related
PHP Version: 5.6.32 OS: centos6
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ycgambo at outlook dot com
New email:
PHP Version: OS:

 

 [2017-11-21 06:21 UTC] ycgambo at outlook dot com
Description:
------------
---
From manual page: http://www.php.net/function.iterator-apply
---

the 3rd parameter `args` of iterator-apply doesn't passed to callback as an array.

Test script:
---------------
<?php
$ai = new ArrayIterator(range(0, 2));

iterator_apply($ai, function($args) {
    var_dump($args);
    return true;
}, array(1, 2));


Expected result:
----------------
array(2) {
  [0] =>
  int(1)
  [1] =>
  int(2)
}
array(2) {
  [0] =>
  int(1)
  [1] =>
  int(2)
}
array(2) {
  [0] =>
  int(1)
  [1] =>
  int(2)
}

Actual result:
--------------
int(1)
int(1)
int(1)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-11-21 07:17 UTC] requinix@php.net
-Summary: iterator-apply parameter passed unexpected +Summary: Clarification for how iterator_apply's $args are passed to the $function -Status: Open +Status: Verified
 [2017-11-21 07:17 UTC] requinix@php.net
$args is an array and each of its elements are passed to the callback as separate arguments.
https://3v4l.org/6Qrnk
 [2017-11-22 06:31 UTC] ycgambo at outlook dot com
Got it, thanks for reply.
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC