[TYPO3-core] RFC #14488: prioriCalc no longer working correctly due to changes in rev 7592

Xavier Perseguers typo3 at perseguers.ch
Thu May 27 07:50:29 CEST 2010


Hi,

> I read diff of changeset 7592 and I have following comments (yes, I
> should put them in original thread but this post is kinda better
> readable and points out a bug):
>
> [...]
>
> Otherwise the remaining looks good to me.

Something worries me a bit though.

Many calls of while(list()) _at the beginning of functions_ with provided arguments (and without reset() first) were simply replaced by foreach.

However following code shows a possible side effect:

<?php

function foo($arr) {
         while(list(,$v) = each($arr)) {
                 echo $v . "\n";
         }
}

$a = array(1,2,3,4);
list(,$value) = each($a);

foo($a);

?>

which prints 2 3 4 instead of 1 2 3 4 which we would get with current state using foreach.

Now you may say that the core team would never have written such code with side effect but what worries me is a chunk from changeset 7592 in class.t3lib_tsparser_ext.php:

  	function ext_getSearchKeys($arr, $depth_in, $searchString, $keyArray)		{
-		reset($arr);
  		$keyArr=array();
-		while (list($key,)=each($arr))	{
+		foreach ($arr as $key => $value) {

What worries me here is that someone explicitly reset $arr at the beginning of the method while other similar code with a while(list()) at the beginning of a method did not do that. What does that 
mean? The array pointer was known to be safely at the beginning? Or is there cases where the parent caller did some "each()" call before?

-- 
Xavier Perseguers
http://xavier.perseguers.ch/en


More information about the TYPO3-team-core mailing list