Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 7 Throwable support: Error handling type declarations have been removed and work in PHP 5.x and PHP 7.x #106

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Bugsnag/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,9 @@ public function setSendCode($sendCode)
* @param Array $metaData optional metaData to send with this error
* @param String $severity optional severity of this error (fatal/error/warning/info)
*/
public function notifyException(Exception $exception, array $metaData = null, $severity = null)
public function notifyException($throwable, array $metaData = null, $severity = null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation for this method should probably be updated to indicate a throwable is accepted here

{
$error = Bugsnag_Error::fromPHPException($this->config, $this->diagnostics, $exception);
$error = Bugsnag_Error::fromPHPThrowable($this->config, $this->diagnostics, $throwable);
$error->setSeverity($severity);

$this->notify($error, $metaData);
Expand All @@ -479,13 +479,13 @@ public function notifyError($name, $message, array $metaData = null, $severity =
}

// Exception handler callback, should only be called internally by PHP's set_exception_handler
public function exceptionHandler($exception)
public function exceptionHandler($throwable)
{
if(!$this->config->autoNotify) {
return;
}

$error = Bugsnag_Error::fromPHPException($this->config, $this->diagnostics, $exception);
$error = Bugsnag_Error::fromPHPThrowable($this->config, $this->diagnostics, $throwable);
$error->setSeverity("error");
$this->notify($error);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Bugsnag/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public static function fromPHPError(Bugsnag_Configuration $config, Bugsnag_Diagn
return $error;
}

public static function fromPHPException(Bugsnag_Configuration $config, Bugsnag_Diagnostics $diagnostics, Exception $exception)
public static function fromPHPThrowable(Bugsnag_Configuration $config, Bugsnag_Diagnostics $diagnostics, $throwable)
{
$error = new Bugsnag_Error($config, $diagnostics);
$error->setPHPException($exception);
$error->setPHPException($throwable);

return $error;
}
Expand Down Expand Up @@ -143,7 +143,7 @@ public function setMetaData($metaData)
public function setPrevious($exception)
{
if ($exception) {
$this->previous = Bugsnag_Error::fromPHPException($this->config, $this->diagnostics, $exception);
$this->previous = Bugsnag_Error::fromPHPThrowable($this->config, $this->diagnostics, $exception);
}

return $this;
Expand Down
2 changes: 1 addition & 1 deletion tests/Bugsnag/ErrorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function testPreviousException()
if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
$exception = new Exception("secondly", 65533, new Exception("firstly"));

$error = Bugsnag_Error::fromPHPException($this->config, $this->diagnostics, $exception);
$error = Bugsnag_Error::fromPHPThrowable($this->config, $this->diagnostics, $exception);

$errorArray = $error->toArray();

Expand Down