Skip to content
This repository

Discourage use of the silence operator. #1390

Closed
wants to merge 2 commits into from

3 participants

Rouven Weßling Sam Moffatt Louis Landry
Rouven Weßling
Collaborator

No description provided.

Sam Moffatt

Not sure I entirely agree, PHP's obsession with returning PHP warnings/errors with the actual error message being in the warning (only partially following the C convention here). The only way to work around this and get useful information is to use $php_errormsg however the PHP example includes the use of the silence operate in it's canonical example:
http://us2.php.net/manual/en/reserved.variables.phperrormsg.php

Rouven Weßling
Collaborator

I agree we'll never be able to completely get rid of them (at least not with PHP's current error capabilities). But there are a number of places where we wouldn't need them if we'd use a isset() or other checks like that. That's why this would only add a warning, not an error.

Louis Landry LouisLandry commented on the diff October 08, 2012
libraries/joomla/string/string.php
@@ -15,9 +15,9 @@
15 15
 if (extension_loaded('mbstring'))
16 16
 {
17 17
 	// Make sure to suppress the output in case ini_set is disabled
18  
-	@ini_set('mbstring.internal_encoding', 'UTF-8');
1

These I'm not sure I like. The others I'm fine with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Louis Landry

This is no longer mergeable. Additionally I have reservations on the silence operator being used on the mbstring settings. If errors, notices, or warnings are suppressed for that we don't have any sort of backup to know what went wrong in using the mbstring functions.

I'm going to close this one for now until you can get it rebased @realityking. Do that and we can continue the discussion. Remove those supression operators on the ini_set() calls for mbstring and I'll just merge it. Reopen when you are ready, thanks!

Louis Landry LouisLandry closed this November 08, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
1  build/phpcs/Joomla/ruleset.xml
@@ -47,6 +47,7 @@
47 47
  <rule ref="Generic.PHP.DisallowShortOpenTag"/>
48 48
  <rule ref="Generic.PHP.DeprecatedFunctions"/>
49 49
  <rule ref="Generic.PHP.ForbiddenFunctions"/>
  50
+ <rule ref="Generic.PHP.NoSilencedErrors"/>
50 51
 
51 52
  <rule ref="Squiz.Operators.IncrementDecrementUsage"/>
52 53
 
13  libraries/joomla/document/document.php
@@ -383,16 +383,13 @@ public function getMetaData($name, $httpEquiv = false)
383 383
 		{
384 384
 			$result = $this->getDescription();
385 385
 		}
  386
+		elseif ($httpEquiv == true)
  387
+		{
  388
+			$result = isset($this->_metaTags['http-equiv'][$name]) ? $this->_metaTags['http-equiv'][$name] : null;
  389
+		}
386 390
 		else
387 391
 		{
388  
-			if ($httpEquiv == true)
389  
-			{
390  
-				$result = @$this->_metaTags['http-equiv'][$name];
391  
-			}
392  
-			else
393  
-			{
394  
-				$result = @$this->_metaTags['standard'][$name];
395  
-			}
  392
+			$result = isset($this->_metaTags['standard'][$name]) ? $this->_metaTags['standard'][$name] : null;
396 393
 		}
397 394
 
398 395
 		return $result;
6  libraries/joomla/string/string.php
@@ -15,9 +15,9 @@
15 15
 if (extension_loaded('mbstring'))
16 16
 {
17 17
 	// Make sure to suppress the output in case ini_set is disabled
18  
-	@ini_set('mbstring.internal_encoding', 'UTF-8');
19  
-	@ini_set('mbstring.http_input', 'UTF-8');
20  
-	@ini_set('mbstring.http_output', 'UTF-8');
  18
+	ini_set('mbstring.internal_encoding', 'UTF-8');
  19
+	ini_set('mbstring.http_input', 'UTF-8');
  20
+	ini_set('mbstring.http_output', 'UTF-8');
21 21
 }
22 22
 
23 23
 // Same for iconv
4  libraries/legacy/application/application.php
@@ -663,10 +663,10 @@ public function login($credentials, $options = array())
663 663
 			if (!in_array(false, $results, true))
664 664
 			{
665 665
 				// Set the remember me cookie if enabled.
666  
-				if (isset($options['remember']) && $options['remember'])
  666
+				if (isset($options['remember']) && $options['remember'] && isset($_SERVER['HTTP_USER_AGENT']))
667 667
 				{
668 668
 					// Create the encryption key, apply extra hardening using the user agent string.
669  
-					$privateKey = self::getHash(@$_SERVER['HTTP_USER_AGENT']);
  669
+					$privateKey = self::getHash($_SERVER['HTTP_USER_AGENT']);
670 670
 
671 671
 					$key = new JCryptKey('simple', $privateKey, $privateKey);
672 672
 					$crypt = new JCrypt(new JCryptCipherSimple, $key);
6  libraries/legacy/html/menu.php
@@ -240,7 +240,7 @@ public static function linkoptions($all = false, $unassigned = false)
240 240
 		foreach ($mitems as $v)
241 241
 		{
242 242
 			$pt = $v->parent_id;
243  
-			$list = @$children[$pt] ? $children[$pt] : array();
  243
+			$list = isset($children[$pt]) ? $children[$pt] : array();
244 244
 			array_push($list, $v);
245 245
 			$children[$pt] = $list;
246 246
 		}
@@ -308,7 +308,7 @@ public static function linkoptions($all = false, $unassigned = false)
308 308
 	 */
309 309
 	public static function treerecurse($id, $indent, $list, &$children, $maxlevel = 9999, $level = 0, $type = 1)
310 310
 	{
311  
-		if (@$children[$id] && $level <= $maxlevel)
  311
+		if (isset($children[$id]) && $level <= $maxlevel)
312 312
 		{
313 313
 			foreach ($children[$id] as $v)
314 314
 			{
@@ -336,7 +336,7 @@ public static function treerecurse($id, $indent, $list, &$children, $maxlevel =
336 336
 
337 337
 				$list[$id] = $v;
338 338
 				$list[$id]->treename = $indent . $txt;
339  
-				$list[$id]->children = count(@$children[$id]);
  339
+				$list[$id]->children = count($children[$id]);
340 340
 				$list = self::TreeRecurse($id, $indent . $spacer, $list, $children, $maxlevel, $level + 1, $type);
341 341
 			}
342 342
 		}
11  libraries/legacy/view/legacy.php
@@ -255,8 +255,15 @@ public function assign()
255 255
 		JLog::add(__METHOD__ . ' is deprecated. Use native PHP syntax.', JLog::WARNING, 'deprecated');
256 256
 
257 257
 		// Get the arguments; there may be 1 or 2.
258  
-		$arg0 = @func_get_arg(0);
259  
-		$arg1 = @func_get_arg(1);
  258
+		$arg0 = func_get_arg(0);
  259
+		if (func_num_args() > 1)
  260
+		{
  261
+			$arg1 = func_get_arg(1);
  262
+		}
  263
+		else
  264
+		{
  265
+			$arg1 = null;
  266
+		}
260 267
 
261 268
 		// Assign by object
262 269
 		if (is_object($arg0))
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.