diff --git a/libraries/src/Http/Transport/SocketTransport.php b/libraries/src/Http/Transport/SocketTransport.php index a1c448856272a..6871ff34cf892 100644 --- a/libraries/src/Http/Transport/SocketTransport.php +++ b/libraries/src/Http/Transport/SocketTransport.php @@ -283,32 +283,23 @@ protected function connect(Uri $uri, $timeout = null) $timeout = ini_get('default_socket_timeout'); } - // Capture PHP errors - $php_errormsg = ''; - $track_errors = ini_get('track_errors'); - ini_set('track_errors', true); - // PHP sends a warning if the uri does not exists; we silence it and throw an exception instead. // Attempt to connect to the server $connection = @fsockopen($host, $port, $errno, $err, $timeout); if (!$connection) { - if (!$php_errormsg) + $lastError = error_get_last(); + $message = sprintf('Could not connect to resource: %s', $uri, $err, $errno); + + if ($lastError !== null) { - // Error but nothing from php? Create our own - $php_errormsg = sprintf('Could not connect to resource: %s', $uri, $err, $errno); + $message = $lastError['message']; } - // Restore error tracking to give control to the exception handler - ini_set('track_errors', $track_errors); - - throw new \RuntimeException($php_errormsg); + throw new \RuntimeException($message); } - // Restore error tracking to what it was before. - ini_set('track_errors', $track_errors); - // Since the connection was successful let's store it in case we need to use it later. $this->connections[$key] = $connection; diff --git a/libraries/src/Http/Transport/StreamTransport.php b/libraries/src/Http/Transport/StreamTransport.php index 675f400ee3791..d686a00905f63 100644 --- a/libraries/src/Http/Transport/StreamTransport.php +++ b/libraries/src/Http/Transport/StreamTransport.php @@ -177,31 +177,22 @@ public function request($method, Uri $uri, $data = null, array $headers = null, $uri->setPass($this->options->get('passwordauth')); } - // Capture PHP errors - $php_errormsg = ''; - $track_errors = ini_get('track_errors'); - ini_set('track_errors', true); - // Open the stream for reading. $stream = @fopen((string) $uri, 'r', false, $context); if (!$stream) { - if (!$php_errormsg) + $lastError = error_get_last(); + $message = sprintf('Could not connect to resource: %s', $uri, $err, $errno); + + if ($lastError !== null) { - // Error but nothing from php? Create our own - $php_errormsg = sprintf('Could not connect to resource: %s', $uri, $err, $errno); + $message = $lastError['message']; } - // Restore error tracking to give control to the exception handler - ini_set('track_errors', $track_errors); - - throw new \RuntimeException($php_errormsg); + throw new \RuntimeException($message); } - // Restore error tracking to what it was before. - ini_set('track_errors', $track_errors); - // Get the metadata for the stream, including response headers. $metadata = stream_get_meta_data($stream); diff --git a/libraries/src/Language/Language.php b/libraries/src/Language/Language.php index e2b7d9e5a5729..4484280bff7d0 100644 --- a/libraries/src/Language/Language.php +++ b/libraries/src/Language/Language.php @@ -824,11 +824,7 @@ protected function parse($filename) // Capture hidden PHP errors from the parsing. if ($this->debug) { - // See https://secure.php.net/manual/en/reserved.variables.phperrormsg.php - $php_errormsg = null; - - $trackErrors = ini_get('track_errors'); - ini_set('track_errors', true); + $oldErrorReporting = error_reporting(E_ALL); } // This was required for https://github.com/joomla/joomla-cms/issues/17198 but not sure what server setup @@ -855,7 +851,7 @@ protected function parse($filename) // Restore error tracking to what it was before. if ($this->debug) { - ini_set('track_errors', $trackErrors); + error_reporting($oldErrorReporting); $this->debugFile($filename); } @@ -888,7 +884,6 @@ public function debugFile($filename) $debug = $this->getDebug(); $this->debug = false; $errors = array(); - $php_errormsg = null; // Open the file as a stream. $file = new \SplFileObject($filename); @@ -949,15 +944,17 @@ public function debugFile($filename) } } + $lastError = error_get_last(); + // Check if we encountered any errors. if (count($errors)) { $this->errorfiles[$filename] = $filename . ' : error(s) in line(s) ' . implode(', ', $errors); } - elseif ($php_errormsg) + elseif ($lastError !== null) { // We didn't find any errors but there's probably a parse notice. - $this->errorfiles['PHP' . $filename] = 'PHP parser errors :' . $php_errormsg; + $this->errorfiles['PHP' . $filename] = 'PHP parser errors :' . $lastError['message']; } $this->debug = $debug;