Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Discourage use of the silence operator. #1390

Closed
wants to merge 2 commits into from

3 participants

@realityking
Collaborator

No description provided.

@pasamio

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

@realityking
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.

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

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
@LouisLandry

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!

@LouisLandry LouisLandry closed this
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.
View
1  build/phpcs/Joomla/ruleset.xml
@@ -47,6 +47,7 @@
<rule ref="Generic.PHP.DisallowShortOpenTag"/>
<rule ref="Generic.PHP.DeprecatedFunctions"/>
<rule ref="Generic.PHP.ForbiddenFunctions"/>
+ <rule ref="Generic.PHP.NoSilencedErrors"/>
<rule ref="Squiz.Operators.IncrementDecrementUsage"/>
View
13 libraries/joomla/document/document.php
@@ -383,16 +383,13 @@ public function getMetaData($name, $httpEquiv = false)
{
$result = $this->getDescription();
}
+ elseif ($httpEquiv == true)
+ {
+ $result = isset($this->_metaTags['http-equiv'][$name]) ? $this->_metaTags['http-equiv'][$name] : null;
+ }
else
{
- if ($httpEquiv == true)
- {
- $result = @$this->_metaTags['http-equiv'][$name];
- }
- else
- {
- $result = @$this->_metaTags['standard'][$name];
- }
+ $result = isset($this->_metaTags['standard'][$name]) ? $this->_metaTags['standard'][$name] : null;
}
return $result;
View
6 libraries/joomla/string/string.php
@@ -15,9 +15,9 @@
if (extension_loaded('mbstring'))
{
// Make sure to suppress the output in case ini_set is disabled
- @ini_set('mbstring.internal_encoding', 'UTF-8');

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
- @ini_set('mbstring.http_input', 'UTF-8');
- @ini_set('mbstring.http_output', 'UTF-8');
+ ini_set('mbstring.internal_encoding', 'UTF-8');
+ ini_set('mbstring.http_input', 'UTF-8');
+ ini_set('mbstring.http_output', 'UTF-8');
}
// Same for iconv
View
4 libraries/legacy/application/application.php
@@ -663,10 +663,10 @@ public function login($credentials, $options = array())
if (!in_array(false, $results, true))
{
// Set the remember me cookie if enabled.
- if (isset($options['remember']) && $options['remember'])
+ if (isset($options['remember']) && $options['remember'] && isset($_SERVER['HTTP_USER_AGENT']))
{
// Create the encryption key, apply extra hardening using the user agent string.
- $privateKey = self::getHash(@$_SERVER['HTTP_USER_AGENT']);
+ $privateKey = self::getHash($_SERVER['HTTP_USER_AGENT']);
$key = new JCryptKey('simple', $privateKey, $privateKey);
$crypt = new JCrypt(new JCryptCipherSimple, $key);
View
6 libraries/legacy/html/menu.php
@@ -240,7 +240,7 @@ public static function linkoptions($all = false, $unassigned = false)
foreach ($mitems as $v)
{
$pt = $v->parent_id;
- $list = @$children[$pt] ? $children[$pt] : array();
+ $list = isset($children[$pt]) ? $children[$pt] : array();
array_push($list, $v);
$children[$pt] = $list;
}
@@ -308,7 +308,7 @@ public static function linkoptions($all = false, $unassigned = false)
*/
public static function treerecurse($id, $indent, $list, &$children, $maxlevel = 9999, $level = 0, $type = 1)
{
- if (@$children[$id] && $level <= $maxlevel)
+ if (isset($children[$id]) && $level <= $maxlevel)
{
foreach ($children[$id] as $v)
{
@@ -336,7 +336,7 @@ public static function treerecurse($id, $indent, $list, &$children, $maxlevel =
$list[$id] = $v;
$list[$id]->treename = $indent . $txt;
- $list[$id]->children = count(@$children[$id]);
+ $list[$id]->children = count($children[$id]);
$list = self::TreeRecurse($id, $indent . $spacer, $list, $children, $maxlevel, $level + 1, $type);
}
}
View
11 libraries/legacy/view/legacy.php
@@ -255,8 +255,15 @@ public function assign()
JLog::add(__METHOD__ . ' is deprecated. Use native PHP syntax.', JLog::WARNING, 'deprecated');
// Get the arguments; there may be 1 or 2.
- $arg0 = @func_get_arg(0);
- $arg1 = @func_get_arg(1);
+ $arg0 = func_get_arg(0);
+ if (func_num_args() > 1)
+ {
+ $arg1 = func_get_arg(1);
+ }
+ else
+ {
+ $arg1 = null;
+ }
// Assign by object
if (is_object($arg0))
Something went wrong with that request. Please try again.