diff --git a/core/Diff.php b/core/Diff.php index a1c5fd6e7..39f61b757 100644 --- a/core/Diff.php +++ b/core/Diff.php @@ -278,15 +278,17 @@ class _DiffEngine if (empty($ymatches[$line])) continue; $matches = $ymatches[$line]; - reset($matches); - while (list ($junk, $y) = each($matches)) + $y = reset($matches); + do { if (empty($this->in_seq[$y])) { - $k = $this->_lcs_pos($y); - USE_ASSERTS && assert($k > 0); - $ymids[$k] = $ymids[$k-1]; - break; - } - while (list ($junk, $y) = each($matches)) { + $k = $this->_lcs_pos($y); + USE_ASSERTS && assert($k > 0); + $ymids[$k] = $ymids[$k - 1]; + break; + } + } while (false !== ($y = next($matches))); + + while (false !== ($y = next($matches))) { if ($y > $this->seq[$k-1]) { USE_ASSERTS && assert($y < $this->seq[$k]); // Optimization: this is a common case: @@ -797,18 +799,19 @@ class Diff $content = str_replace(array(" ","<", ">"),array(" "," <", "> "),$content); $candidateChunks = preg_split("/[\t\r\n ]+/", $content); - while(list($i,$item) = each($candidateChunks)) { + $item = reset($candidateChunks); + do { if(isset($item[0]) && $item[0] == "<") { $newChunk = $item; while($item[strlen($item)-1] != ">") { - list($i,$item) = each($candidateChunks); + $item = next($candidateChunks); $newChunk .= ' ' . $item; } $chunks[] = $newChunk; } else { $chunks[] = $item; } - } + } while (false !== ($item = next($candidateChunks))); return $chunks; } diff --git a/dev/Profiler.php b/dev/Profiler.php index 435c553bb..ef0327ef2 100644 --- a/dev/Profiler.php +++ b/dev/Profiler.php @@ -161,7 +161,7 @@ class Profiler { echo"============================================================================\n"; print( "Calls Time Routine\n"); echo"-----------------------------------------------------------------------------\n"; - while (list ($key, $val) = each ($this->description)) { + foreach ($this->description as $key => $val) { $t = $this->elapsedTime($key); $total = $this->running[$key]; $count = $this->count[$key]; diff --git a/forms/gridfield/GridField.php b/forms/gridfield/GridField.php index d0190411e..4af6a4a6d 100644 --- a/forms/gridfield/GridField.php +++ b/forms/gridfield/GridField.php @@ -337,26 +337,34 @@ class GridField extends FormField { 'before' => true, 'after' => true, ); + $fragmentDeferred = array(); - reset($content); + // TODO: Break the below into separate reducer methods - while(list($contentKey, $contentValue) = each($content)) { - if(preg_match_all('/\$DefineFragment\(([a-z0-9\-_]+)\)/i', $contentValue, $matches)) { - foreach($matches[1] as $match) { + // Continue looping if any placeholders exist + while (array_filter($content, function ($value) { + return preg_match('/\$DefineFragment\(([a-z0-9\-_]+)\)/i', $value); + })) { + foreach ($content as $contentKey => $contentValue) { + // Skip if this specific content has no placeholders + if (!preg_match_all('/\$DefineFragment\(([a-z0-9\-_]+)\)/i', $contentValue, $matches)) { + continue; + } + foreach ($matches[1] as $match) { $fragmentName = strtolower($match); $fragmentDefined[$fragmentName] = true; $fragment = ''; - if(isset($content[$fragmentName])) { + if (isset($content[$fragmentName])) { $fragment = $content[$fragmentName]; } // If the fragment still has a fragment definition in it, when we should defer // this item until later. - if(preg_match('/\$DefineFragment\(([a-z0-9\-_]+)\)/i', $fragment, $matches)) { - if(isset($fragmentDeferred[$contentKey]) && $fragmentDeferred[$contentKey] > 5) { + if (preg_match('/\$DefineFragment\(([a-z0-9\-_]+)\)/i', $fragment, $matches)) { + if (isset($fragmentDeferred[$contentKey]) && $fragmentDeferred[$contentKey] > 5) { throw new LogicException(sprintf( 'GridField HTML fragment "%s" and "%s" appear to have a circular dependency.', $fragmentName, @@ -368,7 +376,7 @@ class GridField extends FormField { $content[$contentKey] = $contentValue; - if(!isset($fragmentDeferred[$contentKey])) { + if (!isset($fragmentDeferred[$contentKey])) { $fragmentDeferred[$contentKey] = 0; } @@ -386,6 +394,7 @@ class GridField extends FormField { } } + // Check for any undefined fragments, and if so throw an exception. // While we're at it, trim whitespace off the elements. @@ -587,7 +596,7 @@ class GridField extends FormField { } else { $classes[] = 'odd'; } - + $this->extend('updateNewRowClasses', $classes, $total, $index, $record); return $classes; diff --git a/model/Hierarchy.php b/model/Hierarchy.php index 42461c95f..1b39ca5c3 100644 --- a/model/Hierarchy.php +++ b/model/Hierarchy.php @@ -247,8 +247,10 @@ class Hierarchy extends DataExtension { $this->markedNodes = array($this->owner->ID => $this->owner); $this->owner->markUnexpanded(); + $node = reset($this->markedNodes); + // foreach can't handle an ever-growing $nodes list - while(list($id, $node) = each($this->markedNodes)) { + do { // first determine the number of children, if it's too high the tree view can't be used // so will will not even bother to display the subtree // this covers two cases: @@ -267,7 +269,7 @@ class Hierarchy extends DataExtension { if($children) foreach($children as $child) $child->markClosed(); break; } - } + } while (false !== ($node = next($this->markedNodes))); return sizeof($this->markedNodes); } diff --git a/thirdparty/Zend/Cache/Backend.php b/thirdparty/Zend/Cache/Backend.php index 469180b71..1a76ff273 100644 --- a/thirdparty/Zend/Cache/Backend.php +++ b/thirdparty/Zend/Cache/Backend.php @@ -63,7 +63,7 @@ class Zend_Cache_Backend */ public function __construct(array $options = array()) { - while (list($name, $value) = each($options)) { + foreach ($options as $name => $value) { $this->setOption($name, $value); } } @@ -78,7 +78,7 @@ class Zend_Cache_Backend public function setDirectives($directives) { if (!is_array($directives)) Zend_Cache::throwException('Directives parameter must be an array'); - while (list($name, $value) = each($directives)) { + foreach ($directives as $name => $value) { if (!is_string($name)) { Zend_Cache::throwException("Incorrect option name : $name"); } diff --git a/thirdparty/Zend/Cache/Core.php b/thirdparty/Zend/Cache/Core.php index 47fa687dd..f8df705ae 100644 --- a/thirdparty/Zend/Cache/Core.php +++ b/thirdparty/Zend/Cache/Core.php @@ -143,7 +143,7 @@ class Zend_Cache_Core Zend_Cache::throwException("Options passed were not an array" . " or Zend_Config instance."); } - while (list($name, $value) = each($options)) { + foreach ($options as $name => $value) { $this->setOption($name, $value); } $this->_loggerSanity(); @@ -158,7 +158,7 @@ class Zend_Cache_Core public function setConfig(Zend_Config $config) { $options = $config->toArray(); - while (list($name, $value) = each($options)) { + foreach ($options as $name => $value) { $this->setOption($name, $value); } return $this; diff --git a/thirdparty/Zend/Cache/Frontend/Class.php b/thirdparty/Zend/Cache/Frontend/Class.php index 91f26ab1d..61d2b3f83 100644 --- a/thirdparty/Zend/Cache/Frontend/Class.php +++ b/thirdparty/Zend/Cache/Frontend/Class.php @@ -107,7 +107,7 @@ class Zend_Cache_Frontend_Class extends Zend_Cache_Core */ public function __construct(array $options = array()) { - while (list($name, $value) = each($options)) { + foreach ($options as $name => $value) { $this->setOption($name, $value); } if ($this->_specificOptions['cached_entity'] === null) { diff --git a/thirdparty/Zend/Cache/Frontend/File.php b/thirdparty/Zend/Cache/Frontend/File.php index 5bc1f35c4..71560a282 100644 --- a/thirdparty/Zend/Cache/Frontend/File.php +++ b/thirdparty/Zend/Cache/Frontend/File.php @@ -88,7 +88,7 @@ class Zend_Cache_Frontend_File extends Zend_Cache_Core */ public function __construct(array $options = array()) { - while (list($name, $value) = each($options)) { + foreach ($options as $name => $value) { $this->setOption($name, $value); } if (!isset($this->_specificOptions['master_files'])) { diff --git a/thirdparty/Zend/Cache/Frontend/Function.php b/thirdparty/Zend/Cache/Frontend/Function.php index dfbcf71e2..5016a0701 100644 --- a/thirdparty/Zend/Cache/Frontend/Function.php +++ b/thirdparty/Zend/Cache/Frontend/Function.php @@ -63,7 +63,7 @@ class Zend_Cache_Frontend_Function extends Zend_Cache_Core */ public function __construct(array $options = array()) { - while (list($name, $value) = each($options)) { + foreach ($options as $name => $value) { $this->setOption($name, $value); } $this->setOption('automatic_serialization', true); diff --git a/thirdparty/Zend/Cache/Frontend/Page.php b/thirdparty/Zend/Cache/Frontend/Page.php index b9bd29fd4..158ecf803 100644 --- a/thirdparty/Zend/Cache/Frontend/Page.php +++ b/thirdparty/Zend/Cache/Frontend/Page.php @@ -129,7 +129,7 @@ class Zend_Cache_Frontend_Page extends Zend_Cache_Core */ public function __construct(array $options = array()) { - while (list($name, $value) = each($options)) { + foreach ($options as $name => $value) { $name = strtolower($name); switch ($name) { case 'regexps':