File tree Expand file tree Collapse file tree 2 files changed +41
-1
lines changed
tests/PHPStan/Rules/Exceptions Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -739,7 +739,11 @@ public function testBug13806(): void
739739 $ this ->analyse ([__DIR__ . '/data/bug-13806.php ' ], [
740740 [
741741 'Dead catch - Throwable is never thrown in the try block. ' ,
742- 28 ,
742+ 53 ,
743+ ],
744+ [
745+ 'Dead catch - Throwable is never thrown in the try block. ' ,
746+ 64 ,
743747 ],
744748 ]);
745749 }
Original file line number Diff line number Diff line change @@ -22,6 +22,42 @@ public function __toString() {
2222
2323castToString (new MyString ());
2424
25+ class ThrowsException {
26+ /** @throws \Exception */
27+ public function __toString (): string {
28+ throw new \Exception ();
29+ }
30+ }
31+
32+ function castThrowsException (ThrowsException $ variable ): string {
33+ try {
34+ $ value = (string ) $ variable ;
35+ } catch (\Throwable ) {
36+ var_dump ("Error thrown during string-conversion! " );
37+ $ value = '' ;
38+ }
39+
40+ return $ value ;
41+ }
42+
43+ class ThrowsVoid {
44+ /** @throws void */
45+ public function __toString (): string {
46+ return 'hello ' ;
47+ }
48+ }
49+
50+ function castThrowsVoid (ThrowsVoid $ variable ): string {
51+ try {
52+ $ value = (string ) $ variable ;
53+ } catch (\Throwable ) {
54+ var_dump ("Error thrown during string-conversion! " );
55+ $ value = '' ;
56+ }
57+
58+ return $ value ;
59+ }
60+
2561function castIntToString (int $ variable ): string {
2662 try {
2763 $ value = (string ) $ variable ;
You can’t perform that action at this time.
0 commit comments