diff --git a/control/Director.php b/control/Director.php index 3ea35b3958c..1c9373fef09 100644 --- a/control/Director.php +++ b/control/Director.php @@ -245,7 +245,7 @@ public static function test($url, $postVars = null, $session = null, $httpMethod Requirements::set_backend(new Requirements_Backend()); // Handle absolute URLs - if (@parse_url($url, PHP_URL_HOST) != '') { + if (parse_url($url, PHP_URL_HOST)) { $bits = parse_url($url); // If a port is mentioned in the absolute URL, be sure to add that into the // HTTP host diff --git a/dev/Debug.php b/dev/Debug.php index 46a0c430f81..65d1ed8e63a 100644 --- a/dev/Debug.php +++ b/dev/Debug.php @@ -401,7 +401,12 @@ public static function showError($errno, $errstr, $errfile, $errline, $errcontex $reporter = self::create_debug_view(); // Coupling alert: This relies on knowledge of how the director gets its URL, it could be improved. - $httpRequest = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : @$_REQUEST['url']; + $httpRequest = null; + if(isset($_SERVER['REQUEST_URI'])) { + $httpRequest = $_SERVER['REQUEST_URI']; + } elseif(isset($_REQUEST['url'])) { + $httpRequest = $_REQUEST['url']; + } if(isset($_SERVER['REQUEST_METHOD'])) $httpRequest = $_SERVER['REQUEST_METHOD'] . ' ' . $httpRequest; $reporter->writeHeader($httpRequest); diff --git a/dev/Log.php b/dev/Log.php index ef70dba89a7..ade21604e3f 100644 --- a/dev/Log.php +++ b/dev/Log.php @@ -167,8 +167,8 @@ public static function log($message, $priority, $extras = null) { $message = array( 'errno' => '', 'errstr' => $message, - 'errfile' => @$lastTrace['file'], - 'errline' => @$lastTrace['line'], + 'errfile' => isset($lastTrace['file']) ? $lastTrace['file'] : null, + 'errline' => isset($lastTrace['line']) ? $lastTrace['line'] : null, 'errcontext' => $trace ); } diff --git a/dev/LogErrorEmailFormatter.php b/dev/LogErrorEmailFormatter.php index 195aefcfd76..b9213005b92 100644 --- a/dev/LogErrorEmailFormatter.php +++ b/dev/LogErrorEmailFormatter.php @@ -66,8 +66,8 @@ public function format($event) { $relfile = Director::makeRelative($errfile); if($relfile && $relfile[0] == '/') $relfile = substr($relfile, 1); - $host = @$_SERVER['HTTP_HOST']; - $uri = @$_SERVER['REQUEST_URI']; + $host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null; + $uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : null; $subject = "[$errorType] in $relfile:{$errline} (http://{$host}{$uri})"; diff --git a/dev/install/install.php5 b/dev/install/install.php5 index a7dc9fbea60..92a90938bdc 100755 --- a/dev/install/install.php5 +++ b/dev/install/install.php5 @@ -386,11 +386,15 @@ class InstallRequirements { */ function findWebserver() { // Try finding from SERVER_SIGNATURE or SERVER_SOFTWARE - $webserver = @$_SERVER['SERVER_SIGNATURE']; - if(!$webserver) $webserver = @$_SERVER['SERVER_SOFTWARE']; + if(!empty($_SERVER['SERVER_SIGNATURE'])) { + $webserver = $_SERVER['SERVER_SIGNATURE']; + } elseif(!empty($_SERVER['SERVER_SOFTWARE'])) { + $webserver = $_SERVER['SERVER_SOFTWARE']; + } else { + return false; + } - if($webserver) return strip_tags(trim($webserver)); - else return false; + return strip_tags(trim($webserver)); } /** @@ -1116,7 +1120,7 @@ class InstallRequirements { $this->testing($testDetails); return true; } else { - if(!@$result['cannotCreate']) { + if(empty($result['cannotCreate'])) { $testDetails[2] .= ". Please create the database manually."; } else { $testDetails[2] .= " (user '$databaseConfig[username]' doesn't have CREATE DATABASE permissions.)"; @@ -1194,7 +1198,7 @@ class InstallRequirements { $section = $testDetails[0]; $test = $testDetails[1]; - $this->tests[$section][$test] = array("error", @$testDetails[2]); + $this->tests[$section][$test] = array("error", isset($testDetails[2]) ? $testDetails[2] : null); $this->errors[] = $testDetails; } @@ -1202,7 +1206,7 @@ class InstallRequirements { $section = $testDetails[0]; $test = $testDetails[1]; - $this->tests[$section][$test] = array("warning", @$testDetails[2]); + $this->tests[$section][$test] = array("warning", isset($testDetails[2]) ? $testDetails[2] : null); $this->warnings[] = $testDetails; } diff --git a/docs/en/howto/phpunit-configuration.md b/docs/en/howto/phpunit-configuration.md index fde20de6db5..4ac184febf0 100644 --- a/docs/en/howto/phpunit-configuration.md +++ b/docs/en/howto/phpunit-configuration.md @@ -71,7 +71,7 @@ Example `mysite/_config.php`: // Customized configuration for running with different database settings. // Ensure this code comes after ConfigureFromEnv.php if(Director::isDev()) { - if($db = @$_GET['db']) { + if(isset($_GET['db']) && ($db = $_GET['db'])) { global $databaseConfig; if($db == 'sqlite3') $databaseConfig['type'] = 'SQLite3Database'; } diff --git a/forms/Form.php b/forms/Form.php index ca38874eb92..2ad6cfbf65e 100644 --- a/forms/Form.php +++ b/forms/Form.php @@ -683,7 +683,7 @@ public function setAttribute($name, $value) { * @return String */ public function getAttribute($name) { - return @$this->attributes[$name]; + if(isset($this->attributes[$name])) return $this->attributes[$name]; } public function getAttributes() { diff --git a/forms/FormField.php b/forms/FormField.php index d69e4219938..4007bc6276e 100644 --- a/forms/FormField.php +++ b/forms/FormField.php @@ -358,7 +358,7 @@ public function setAttribute($name, $value) { */ public function getAttribute($name) { $attrs = $this->getAttributes(); - return @$attrs[$name]; + if(isset($attrs[$name])) return $attrs[$name]; } /** diff --git a/forms/HtmlEditorSanitiser.php b/forms/HtmlEditorSanitiser.php index a4aa1fe4a49..920a750c894 100644 --- a/forms/HtmlEditorSanitiser.php +++ b/forms/HtmlEditorSanitiser.php @@ -62,10 +62,10 @@ protected function addValidElements($validElements) { foreach(explode(',', $validElements) as $validElement) { if(preg_match($elementRuleRegExp, $validElement, $matches)) { - $prefix = @$matches[1]; - $elementName = @$matches[2]; - $outputName = @$matches[3]; - $attrData = @$matches[4]; + $prefix = isset($matches[1]) ? $matches[1] : null; + $elementName = isset($matches[2]) ? $matches[2] : null; + $outputName = isset($matches[3]) ? $matches[3] : null; + $attrData = isset($matches[4]) ? $matches[4] : null; // Create the new element $element = new stdClass(); @@ -91,10 +91,10 @@ protected function addValidElements($validElements) { if(preg_match($attrRuleRegExp, $attr, $matches)) { $attr = new stdClass(); - $attrType = @$matches[1]; - $attrName = str_replace('::', ':', @$matches[2]); - $prefix = @$matches[3]; - $value = @$matches[4]; + $attrType = isset($matches[1]) ? $matches[1] : null; + $attrName = isset($matches[2]) ? str_replace('::', ':', $matches[2]) : null; + $prefix = isset($matches[3]) ? $matches[3] : null; + $value = isset($matches[4]) ? $matches[4] : null; // Required if($attrType === '!') { diff --git a/forms/gridfield/GridField.php b/forms/gridfield/GridField.php index 7a1e3fef483..3e84087b37a 100644 --- a/forms/gridfield/GridField.php +++ b/forms/gridfield/GridField.php @@ -615,7 +615,8 @@ protected function buildColumnDispatch() { public function gridFieldAlterAction($data, $form, SS_HTTPRequest $request) { $html = ''; $data = $request->requestVars(); - $fieldData = @$data[$this->getName()]; + $name = $this->getName(); + $fieldData = isset($data[$name]) ? $data[$name] : null; // Update state from client $state = $this->getState(false); diff --git a/model/Database.php b/model/Database.php index 752eb815346..9ea005ae470 100644 --- a/model/Database.php +++ b/model/Database.php @@ -211,14 +211,16 @@ public function endSchemaUpdate() { foreach($this->schemaUpdateTransaction as $tableName => $changes) { switch($changes['command']) { case 'create': - $this->createTable($tableName, $changes['newFields'], $changes['newIndexes'], $changes['options'], - @$changes['advancedOptions']); + $this->createTable($tableName, $changes['newFields'], $changes['newIndexes'], $changes['options'], + isset($changes['advancedOptions']) ? $changes['advancedOptions'] : null + ); break; case 'alter': $this->alterTable($tableName, $changes['newFields'], $changes['newIndexes'], - $changes['alteredFields'], $changes['alteredIndexes'], $changes['alteredOptions'], - @$changes['advancedOptions']); + $changes['alteredFields'], $changes['alteredIndexes'], $changes['alteredOptions'], + isset($changes['advancedOptions']) ? $changes['advancedOptions'] : null + ); break; } } diff --git a/model/HTMLValue.php b/model/HTMLValue.php index 7888806f420..63e983f1f44 100644 --- a/model/HTMLValue.php +++ b/model/HTMLValue.php @@ -163,9 +163,13 @@ public function setContent($content) { // Reset the document if we're in an invalid state for some reason if (!$this->isValid()) $this->setDocument(null); - return @$this->getDocument()->loadHTML( + $errorState = libxml_use_internal_errors(true); + $result = $this->getDocument()->loadHTML( '' . "$content" ); + libxml_clear_errors(); + libxml_use_internal_errors($errorState); + return $result; } } diff --git a/parsers/ShortcodeParser.php b/parsers/ShortcodeParser.php index c091a835a73..f4f66eda0c0 100644 --- a/parsers/ShortcodeParser.php +++ b/parsers/ShortcodeParser.php @@ -229,8 +229,8 @@ protected function extractTags($content) { 'text' => $match[0][0], 's' => $match[0][1], 'e' => $match[0][1] + strlen($match[0][0]), - 'open' => @$match['open'][0], - 'close' => @$match['close'][0], + 'open' => isset($match['open'][0]) ? $match['open'][0] : null, + 'close' => isset($match['close'][0]) ? $match['close'][0] : null, 'attrs' => $attrs, 'content' => '', 'escaped' => !empty($match['oesc'][0]) || !empty($match['cesc1'][0]) || !empty($match['cesc2'][0]) diff --git a/tests/security/BasicAuthTest.php b/tests/security/BasicAuthTest.php index 649845d0345..686db0b504f 100644 --- a/tests/security/BasicAuthTest.php +++ b/tests/security/BasicAuthTest.php @@ -26,8 +26,8 @@ public function tearDown() { } public function testBasicAuthEnabledWithoutLogin() { - $origUser = @$_SERVER['PHP_AUTH_USER']; - $origPw = @$_SERVER['PHP_AUTH_PW']; + $origUser = isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : null; + $origPw = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : null; unset($_SERVER['PHP_AUTH_USER']); unset($_SERVER['PHP_AUTH_PW']); @@ -40,8 +40,8 @@ public function testBasicAuthEnabledWithoutLogin() { } public function testBasicAuthDoesntCallActionOrFurtherInitOnAuthFailure() { - $origUser = @$_SERVER['PHP_AUTH_USER']; - $origPw = @$_SERVER['PHP_AUTH_PW']; + $origUser = isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : null; + $origPw = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : null; unset($_SERVER['PHP_AUTH_USER']); unset($_SERVER['PHP_AUTH_PW']); @@ -60,8 +60,8 @@ public function testBasicAuthDoesntCallActionOrFurtherInitOnAuthFailure() { } public function testBasicAuthEnabledWithPermission() { - $origUser = @$_SERVER['PHP_AUTH_USER']; - $origPw = @$_SERVER['PHP_AUTH_PW']; + $origUser = isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : null; + $origPw = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : null; $_SERVER['PHP_AUTH_USER'] = 'user-in-mygroup@test.com'; $_SERVER['PHP_AUTH_PW'] = 'wrongpassword'; @@ -83,8 +83,8 @@ public function testBasicAuthEnabledWithPermission() { } public function testBasicAuthEnabledWithoutPermission() { - $origUser = @$_SERVER['PHP_AUTH_USER']; - $origPw = @$_SERVER['PHP_AUTH_PW']; + $origUser = isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : null; + $origPw = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : null; $_SERVER['PHP_AUTH_USER'] = 'user-without-groups@test.com'; $_SERVER['PHP_AUTH_PW'] = 'wrongpassword';