php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72051 The reference in CallbackFilterIterator doesn't work as expected
Submitted: 2016-04-18 17:18 UTC Modified: -
From: oparkhomenko at magecore dot com Assigned:
Status: Closed Package: SPL related
PHP Version: 7.0.5 OS: Irrelevant
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
11 - 7 = ?
Subscribe to this entry?

 
 [2016-04-18 17:18 UTC] oparkhomenko at magecore dot com
Description:
------------
When we use reference on the object property instead of value in callback function of CallbackFilterIterator we expect that we can change this property value inside of the function, but in php 7 this functionality doesn't work.

Test script:
---------------
<?php

$data = [
    [1,2]
];

$callbackTest = new CallbackFilterIterator(new ArrayIterator($data), function (&$current) {
    $current['message'] = 'Test message';
    return true;
});

$callbackTest->rewind();
$data = $callbackTest->current();
$callbackTest->next();
var_dump($data);

Expected result:
----------------
array(3) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  ["message"]=>
  string(12) "Test message"
}

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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-04-19 03:04 UTC] laruence@php.net
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=7648f20de3ea31a4ee720238149af8018c0f908f
Log: Fixed bug #72051 (The reference in CallbackFilterIterator doesn't work as expected)
 [2016-04-19 03:04 UTC] laruence@php.net
-Status: Open +Status: Closed
 [2016-07-20 11:32 UTC] davey@php.net
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=7648f20de3ea31a4ee720238149af8018c0f908f
Log: Fixed bug #72051 (The reference in CallbackFilterIterator doesn't work as expected)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 08:01:29 2024 UTC