Skip to content

Commit

Permalink
Merge pull request #7198 from mbabker/Throwable
Browse files Browse the repository at this point in the history
Change PHP 7 Exception handling to catch Throwable
  • Loading branch information
Thomas Hunziker committed Jun 19, 2015
2 parents 9fb2633 + 5c3e3d4 commit cb62859
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions libraries/cms/error/page.php
Expand Up @@ -19,18 +19,18 @@ class JErrorPage
/**
* Render the error page based on an exception.
*
* @param object $error An Exception or BaseException (PHP 7+) object for which to render the error page.
* @param object $error An Exception or Throwable (PHP 7+) object for which to render the error page.
*
* @return void
*
* @since 3.0
*/
public static function render($error)
{
$expectedClass = PHP_MAJOR_VERSION >= 7 ? 'BaseException' : 'Exception';
$expectedClass = PHP_MAJOR_VERSION >= 7 ? 'Throwable' : 'Exception';
$isException = $error instanceof $expectedClass;

// In PHP 5, the $error object should be an instance of Exception; PHP 7 should be a BaseException
// In PHP 5, the $error object should be an instance of Exception; PHP 7 should be a Throwable implementation
if ($isException)
{
try
Expand Down
2 changes: 1 addition & 1 deletion libraries/joomla/document/error/error.php
Expand Up @@ -53,7 +53,7 @@ public function __construct($options = array())
*/
public function setError($error)
{
$expectedClass = PHP_MAJOR_VERSION >= 7 ? 'BaseException' : 'Exception';
$expectedClass = PHP_MAJOR_VERSION >= 7 ? 'Throwable' : 'Exception';

if ($error instanceof $expectedClass)
{
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/suites/libraries/cms/error/JErrorPageTest.php
Expand Up @@ -64,8 +64,8 @@ public function testEnsureTheErrorPageIsCorrectlyRenderedWithEngineExceptions()
$this->markTestSkipped('Test only applies to PHP 7+');
}

// Create an Exception to inject into the method
$exception = new EngineException('Testing JErrorPage::render()', 500);
// Create an Error to inject into the method
$exception = new Error('Testing JErrorPage::render()', 500);

// The render method echoes the output, so catch it in a buffer
ob_start();
Expand Down

0 comments on commit cb62859

Please sign in to comment.