-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change the way PHP7 exception aliasing works
Summary: fixes #7537 fixes #6747 Old approach: when parsing, replace `Throwable` with `__SystemLib\Throwable` New approach: when loading the process, actually create `\Throwable` as an alias of `\__SystemLib\Throwable` get_class() and messages still say systemlib, but this is an improvement. Reviewed By: mofarrell Differential Revision: D5031367 fbshipit-source-id: 4985318804c5c5c190cc8141d721e3d3408fb21b
- Loading branch information
1 parent
e32d324
commit 29fc86f
Showing
9 changed files
with
96 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
class Error implements Throwable { | ||
use BaseException; | ||
/** | ||
* ( excerpt from http://php.net/manual/en/exception.construct.php ) | ||
* | ||
* Constructs the Exception. | ||
* | ||
* @message mixed The Exception message to throw. | ||
* @code mixed The Exception code. | ||
* @previous mixed The previous exception used for the exception | ||
* chaining. | ||
*/ | ||
public function __construct($message = '', $code = 0, | ||
\__SystemLib\Throwable $previous = null) { | ||
|
||
// Child classes may just override the protected property | ||
// without implementing a constructor or calling parent one. | ||
// In this case we should not override it from the param. | ||
|
||
if ($message !== '' || $this->message === '') { | ||
$this->message = $message; | ||
} | ||
|
||
if ($code !== 0 || $this->code === 0) { | ||
$this->code = $code; | ||
} | ||
|
||
$this->previous = $previous; | ||
} | ||
} | ||
|
||
class ArithmeticError extends Error {} | ||
class AssertionError extends Error {} | ||
class DivisionByZeroError extends Error {} | ||
class ParseError extends Error {} | ||
class TypeError extends Error {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
interface Throwable { | ||
public function getMessage(): string; | ||
public function getCode(): int; | ||
public function getFile(): string; | ||
public function getLine(): int; | ||
public function getTrace(): array; | ||
public function getTraceAsString(): string; | ||
public function getPrevious(): Throwable; | ||
public function __toString(): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
hphp/test/slow/php7_backported/engine-exceptions/throwable_namespace_001.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace Foo; | ||
$y = 'Throwable'; | ||
|
||
$x = new \Exception(); | ||
var_dump($x instanceof \Throwable); | ||
var_dump($x instanceof Throwable); | ||
var_dump($x instanceof $y); |
3 changes: 3 additions & 0 deletions
3
hphp/test/slow/php7_backported/engine-exceptions/throwable_namespace_001.php.expect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
bool(true) | ||
bool(false) | ||
bool(true) |
8 changes: 8 additions & 0 deletions
8
hphp/test/slow/php7_backported/engine-exceptions/throwable_namespace_002.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
namespace test; | ||
|
||
function a(\Throwable $t) { | ||
var_dump(get_class($t)); | ||
} | ||
|
||
a(new \RuntimeException('foo')); |
1 change: 1 addition & 0 deletions
1
hphp/test/slow/php7_backported/engine-exceptions/throwable_namespace_002.php.expect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
string(16) "RuntimeException" |
29fc86f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error.php and Throwable.php shouldn't be here, fixing.