php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76343 array_walk myth
Submitted: 2018-05-15 17:02 UTC Modified: 2018-05-15 18:38 UTC
From: young dot inbox at gmail dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 7.2.5 OS: Ubuntu
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: young dot inbox at gmail dot com
New email:
PHP Version: OS:

 

 [2018-05-15 17:02 UTC] young dot inbox at gmail dot com
Description:
------------
After updating from PHP 7.0.* to 7.2.5 next code start failing with

PHP Warning:  ExcelSheet::writeRow(): Failed to write cell in row 0, column 0 with error 'ok' in /home/ddc/young/htdocs/2.php on line 18


It use https://github.com/iliaal/php_excel module and you may think that the problem with this module, but this not true.

If i will comment array_walk, which in this case NOT changing data - it will work fine

With array_walk it gives error

but data array is the same with and without array_walk call

so array_walk call changing not only the data but something invisible in addition, but should not
 

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

$data = array (
	0 => 'test me hard'
);


$xlBook = new \ExcelBook(null, null, true);
$xlBook->setLocale('UTF-8');
$xlSheet1 = $xlBook->addSheet('Sheet1');

var_dump($data);
array_walk($data, function(&$field) {
		$field = (string)$field;
	});
var_dump($data);

$xlSheet1->writeRow(0, $data);


Expected result:
----------------
Same result with and without array_walk

Actual result:
--------------
Error with array_walk and success without 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-05-15 17:23 UTC] spam2 at rhsoft dot net
function(&$field)

don't use references and try to be smarter then the ZendEngine wich is based on copy-on-write - references easily have side-effects you don't realize for no nebefint in 99.999% of all usecases
 [2018-05-15 17:28 UTC] young dot inbox at gmail dot com
it's still reproducible without links

<?php

$data = array (
	0 => 'test me hard'
);

function my_to_string($inp) {
	return (string)$inp;
}

$xlBook = new \ExcelBook(null, null, true);
$xlBook->setLocale('UTF-8');
$xlSheet1 = $xlBook->addSheet('Sheet1');

var_dump($data);
array_walk($data, 'my_to_string');
var_dump($data);

$xlSheet1->writeRow(0, $data);
 [2018-05-15 18:38 UTC] bwoebi@php.net
-Status: Open +Status: Not a bug
 [2018-05-15 18:38 UTC] bwoebi@php.net
This is a bug in the extension, which does not support references. Please file a bug there, it's missing a ZVAL_DEREF() in the array processing function.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Mon Apr 06 21:01:23 2020 UTC