Commit add612f6 authored by Bong Cosca's avatar Bong Cosca
Browse files

Bug fix with test case: PHP globals passed by reference in hive() result (Issue #424)

parent 9d69723c
Loading
Loading
Loading
Loading
+24 −6
Original line number Diff line number Diff line
@@ -452,7 +452,8 @@ final class Base {
				foreach ($arg as $key=>$val) {
					$str.=($str?',':'').
						($num?'':($this->stringify($key).'=>')).
						($arg==$val?'*RECURSION*':$this->stringify($val));
						($arg==$val && !is_scalar($val)?
							'*RECURSION*':$this->stringify($val));
				}
				return 'array('.$str.')';
			default:
@@ -1842,6 +1843,27 @@ class View extends Prefab {
		return ob_get_clean();
	}

	/**
	*	Return dereferenced value
	*	@return mixed
	*	@param mixed
	**/
	function deref($arg) {
		if (is_object($arg)) {
			// Not all objects are cloneable
			$arg=(object)(array)$arg;
			foreach (get_object_vars($arg) as $key=>$val)
				$arg->$key=$this->deref($val);
			return $arg;
		}
		if (is_array($arg)) {
			foreach ($arg as $key=>$val)
				$arg[$key]=$this->deref($val);
			return $arg;
		}
		return json_decode(json_encode($arg));
	}

	/**
	*	Render template
	*	@return string
@@ -1857,11 +1879,7 @@ class View extends Prefab {
					@session_start();
				$fw->sync('SESSION');
				if (!$hive)
					foreach ($fw->hive() as $key=>$val) {
						$hive[$key]=$val;
						if (is_array($val))
							$hive[$key]=(array)(object)$val;
					}
					$hive=$this->deref($fw->hive());
				if ($fw->get('ESCAPE'))
					$hive=$fw->esc($hive);
				if (PHP_SAPI!='cli')
+1 −5
Original line number Diff line number Diff line
@@ -377,11 +377,7 @@ class Template extends View {
					@session_start();
				$fw->sync('SESSION');
				if (!$hive)
					foreach ($fw->hive() as $key=>$val) {
						$hive[$key]=$val;
						if (is_array($val))
							$hive[$key]=(array)(object)$val;
					}
					$hive=$this->deref($fw->hive());
				if ($fw->get('ESCAPE'))
					$hive=$fw->esc($hive);
				if (PHP_SAPI!='cli')