Browse Source

Defensive programming: protected against the Notice "array to string conversion" that appears in PHP 5.4 (thus not on every systems)

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@3002 a333f486-631f-4898-b8df-5754b55c2be0
romainq 11 years ago
parent
commit
03ac608191
2 changed files with 13 additions and 6 deletions
  1. 5 1
      application/portalwebpage.class.inc.php
  2. 8 5
      application/webpage.class.inc.php

+ 5 - 1
application/portalwebpage.class.inc.php

@@ -558,7 +558,11 @@ EOF
 		$this->add("<p align=\"right\"><input type=\"submit\" value=\"".Dict::S('UI:Button:Search')."\"></p>\n");
 		foreach($aExtraParams as $sName => $sValue)
 		{
-			$this->add("<input type=\"hidden\" name=\"$sName\" value=\"$sValue\" />\n");
+			// Note: use DumpHiddenParams() to transmit arrays as hidden params
+			if (is_scalar($sValue))
+			{
+				$this->add("<input type=\"hidden\" name=\"$sName\" value=\"$sValue\" />\n");
+			}
 		}
 	//	$this->add($oAppContext->GetForForm());
 		$this->add("</form>\n");

+ 8 - 5
application/webpage.class.inc.php

@@ -1,5 +1,5 @@
 <?php
-// Copyright (C) 2010-2012 Combodo SARL
+// Copyright (C) 2010-2013 Combodo SARL
 //
 //   This file is part of iTop.
 //
@@ -497,13 +497,16 @@ class WebPage implements Page
 	/**
 	 * Build a series of hidden field[s] from an array
 	 */
-	 // By Rom - je verrais bien une serie d'outils pour gerer des parametres que l'on retransmet entre pages d'un wizard...
-	 //          ptet deriver webpage en webwizard
 	public function add_input_hidden($sLabel, $aData)
 	{
-		foreach($aData as $sKey=>$sValue)
+		foreach($aData as $sKey => $sValue)
 		{
-			$this->add("<input type=\"hidden\" name=\"".$sLabel."[$sKey]\" value=\"$sValue\">");
+			// Note: protection added to protect against the Notice 'array to string conversion' that appeared with PHP 5.4
+			// (this function seems unused though!)
+			if (is_scalar($sValue))
+			{
+				$this->add("<input type=\"hidden\" name=\"".$sLabel."[$sKey]\" value=\"$sValue\">");
+			}
 		}
 	}