From 9ea459787e305b618c5004b9f1b23b6a8a09f3eb Mon Sep 17 00:00:00 2001 From: Matt Pass Date: Fri, 24 Oct 2014 09:23:52 +0100 Subject: [PATCH] Polyfill added for array_replace_recursive This is natively available in PHP 5.3+ --- lib/settings-common.php | 30 ++++++++++++++++++++++++++++++ lib/settings.php | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/settings-common.php b/lib/settings-common.php index e21ef6a..eb82576 100644 --- a/lib/settings-common.php +++ b/lib/settings-common.php @@ -128,4 +128,34 @@ function toUTF8noBOM($string,$message) { } return $string; } + +// Polyfill for array_replace_recursive, which is in PHP 5.3+ +if (!function_exists('array_replace_recursive')) { + function array_replace_recursive($base, $replacements) { + foreach (array_slice(func_get_args(), 1) as $replacements) { + $bref_stack = array(&$base); + $head_stack = array($replacements); + + do { + end($bref_stack); + + $bref = &$bref_stack[key($bref_stack)]; + $head = array_pop($head_stack); + + unset($bref_stack[key($bref_stack)]); + + foreach (array_keys($head) as $key) { + if (isset($key, $bref) && is_array($bref[$key]) && is_array($head[$key])) { + $bref_stack[] = &$bref[$key]; + $head_stack[] = $head[$key]; + } else { + $bref[$key] = $head[$key]; + } + } + } while(count($head_stack)); + } + + return $base; + } +} ?> \ No newline at end of file diff --git a/lib/settings.php b/lib/settings.php index e092985..abd01d5 100644 --- a/lib/settings.php +++ b/lib/settings.php @@ -45,7 +45,7 @@ include(dirname(__FILE__)."/../lang/english.php"); $englishText = $text; // Load chosen language ontop to replace English include(dirname(__FILE__)."/../lang/english.php"); -$text = array_replace_recursive ($englishText, $text); +$text = array_replace_recursive($englishText, $text); $_SESSION['text'] = $text; // Login not required or we're in demo mode and have password set in our settings, log us straight in