Bug #20995

stripSlashesOnArray creates references where you want copies

Added by Ernesto Baschny about 10 years ago. Updated over 9 years ago.

Status:
Closed
Priority:
Should have
Category:
-
Target version:
-
Start date:
2009-09-04
Due date:
% Done:

0%

TYPO3 Version:
4.2
PHP Version:
5.2
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

In newer TYPO3 versions the class t3lib_div::stripSlashesOnArray has been optimized for performance, using a foreach loop where it used to be a while loop. The new version works on references instead of copying the array.

Problem:
After calling this function on a normal array, the array itself contains only references to the values it contained before. This ist quite ugly, cause you can't work on a copy without changing the original data any more.

Proposed Solution:
If you unset the reference at the end of foreach, you can go on using the array as before. This is recommended to do by the php.net documentation (in a big red "Warning" box) when using references in a "foreach" loop.

Issue might arise on any extension that makes use of t3lib_div::_GP. Bug was first noticed when trying to save mm-table-relations using sr_feuser_register:

here:
function parseOutgoingData($origArr = array()) {
(...)
$parsedArr = $origArr;

$parsedArr is a COPY of our $this->dataArr, but it will modify the values from the original dataArr.

Since this is pretty difficult to test, attached is a very simple plugin which can be added to a page and it will explain and demonstrate the bug in "action".

Trouble was introduced in rev.3216 (feature #16375):
http://forge.typo3.org/repositories/revision/typo3v4-core/3216

So it was first included in 4.2.0beta2.
(issue imported from #M11876)

11876.diff View (442 Bytes) Administrator Admin, 2009-09-04 15:10

T3X_cron_bugdemo-1_0_0-z-200909041511.t3x (3.13 KB) Administrator Admin, 2009-09-04 15:11

test-foreach-reference-bug.php View (807 Bytes) Administrator Admin, 2009-09-21 10:21


Related issues

Related to TYPO3 Core - Bug #21361: Update required tables COMPARE doesn't work in 4.2.10 Closed 2009-10-26

History

#1 Updated by Ernesto Baschny about 10 years ago

Attached test-foreach-reference-bug.php can be used to isolately check the behaviour under different PHP environments. My tests were done in PHP 5.2.0 (debian). Other environments might have a different (e.g. correct) behaviour, thus not exposing this bug.

Run test-foreach-reference-bug.php, then edit it and comment the "unset" in and see if it fixes the behaviour.

#2 Updated by Ernesto Baschny about 10 years ago

Commited to trunk rev. 6328 (4.3 beta3) and TYPO3 4.2 rev 6329 (4.2.11).

Also available in: Atom PDF