forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RFC] implement throws type for functions and methods
- Loading branch information
Showing
28 changed files
with
1,374 additions
and
927 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--TEST-- | ||
Testing basic exception type compiler wrong type | ||
--FILE-- | ||
<?php | ||
function () throws int { } | ||
?> | ||
--EXPECTF-- | ||
Fatal error: Throws type must be an object in %s on line 2 | ||
|
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,10 @@ | ||
--TEST-- | ||
Testing basic exception type compiler pass | ||
--FILE-- | ||
<?php | ||
function test () throws Exception {} | ||
?> | ||
OK | ||
--EXPECT-- | ||
OK | ||
|
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,12 @@ | ||
--TEST-- | ||
Testing basic exception type compiler pass with return | ||
--FILE-- | ||
<?php | ||
function test () : int throws Exception { | ||
return 1; | ||
} | ||
?> | ||
OK | ||
--EXPECT-- | ||
OK | ||
|
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,12 @@ | ||
--TEST-- | ||
Testing basic exception type compiler pass with param | ||
--FILE-- | ||
<?php | ||
function test (int $param) throws Exception { | ||
return $param; | ||
} | ||
?> | ||
OK | ||
--EXPECT-- | ||
OK | ||
|
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,21 @@ | ||
--TEST-- | ||
Testing exception type compiler fail inheritance remove throws | ||
--FILE-- | ||
<?php | ||
class A { | ||
public function throwing () throws Exception { | ||
|
||
} | ||
} | ||
|
||
class B extends A { | ||
public function throwing() { | ||
|
||
} | ||
} | ||
?> | ||
--EXPECTF-- | ||
Fatal error: Declaration of B::throwing() must be compatible with A::throwing() throws Exception in %s on line 12 | ||
|
||
|
||
|
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,21 @@ | ||
--TEST-- | ||
Testing exception type compiler pass inheritance add throws | ||
--FILE-- | ||
<?php | ||
class A { | ||
public function throwing () { | ||
|
||
} | ||
} | ||
|
||
class B extends A { | ||
public function throwing() throws Exception { | ||
|
||
} | ||
} | ||
?> | ||
OK | ||
--EXPECT-- | ||
OK | ||
|
||
|
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,21 @@ | ||
--TEST-- | ||
Testing exception type compiler fail inheritance changes throws | ||
--FILE-- | ||
<?php | ||
class A { | ||
public function throwing () throws Exception { | ||
|
||
} | ||
} | ||
|
||
class B extends A { | ||
public function throwing() throws FancyException { | ||
|
||
} | ||
} | ||
?> | ||
--EXPECTF-- | ||
Fatal error: Declaration of B::throwing() throws FancyException must be compatible with A::throwing() throws Exception in %s on line 12 | ||
|
||
|
||
|
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,20 @@ | ||
--TEST-- | ||
Testing exception type executor fail | ||
--DESCRIPTION-- | ||
I have no idea how to update Optimizer, so temporarily disabled it | ||
--INI-- | ||
opcache.optimization_level=0 | ||
--FILE-- | ||
<?php | ||
function test () throws FancyException { | ||
throw new Exception(); | ||
} | ||
test(); | ||
?> | ||
--EXPECTF-- | ||
Fatal error: Uncaught TypeError: Exception thrown by test() expected to be an instance of FancyException, instance of Exception thrown in %s:3 | ||
Stack trace: | ||
#0 %s(5): test() | ||
#1 {main} | ||
thrown in %s on line 3 | ||
|
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,17 @@ | ||
--TEST-- | ||
Testing exception type executor pass | ||
--FILE-- | ||
<?php | ||
class FancyException extends Exception {} | ||
|
||
function test () throws FancyException { | ||
throw new FancyException(); | ||
} | ||
|
||
try { | ||
test(); | ||
} catch (FancyException $ex) {} | ||
?> | ||
OK | ||
--EXPECT-- | ||
OK |
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,17 @@ | ||
--TEST-- | ||
Testing exception type executor with return pass | ||
--FILE-- | ||
<?php | ||
class FancyException extends Exception {} | ||
|
||
function test () : int throws FancyException { | ||
throw new FancyException(); | ||
} | ||
|
||
try { | ||
test(); | ||
} catch (FancyException $ex) {} | ||
?> | ||
OK | ||
--EXPECT-- | ||
OK |
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,15 @@ | ||
--TEST-- | ||
Testing exception type executor with return and param pass | ||
--FILE-- | ||
<?php | ||
function test (int $param) : int throws Exception { | ||
return $param; | ||
} | ||
|
||
try { | ||
test(10); | ||
} catch (FancyException $ex) {} | ||
?> | ||
OK | ||
--EXPECT-- | ||
OK |
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
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
Oops, something went wrong.