Bug #76343 [Opn->Nab]: array_walk myth

From: Date: Tue, 15 May 2018 18:38:45 +0000
Subject: Bug #76343 [Opn->Nab]: array_walk myth
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-215269@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76343&edit=1 ID: 76343 Updated by: bwoebi@php.net Reported by: young dot inbox at gmail dot com Summary: array_walk myth -Status: Open +Status: Not a bug Type: Bug Package: Arrays related Operating System: Ubuntu PHP Version: 7.2.5 Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2018-05-15 17:28:35] 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 17:23:08] 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:02:40] 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 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=76343&edit=1

« previous php.bugs (#215269) next »