Skip to content

Commit 7676b10

Browse files
committed
throwing exceptions from __toString() is allowed since PHP 7.4
1 parent 815a414 commit 7676b10

File tree

6 files changed

+18
-0
lines changed

6 files changed

+18
-0
lines changed

src/PhpGenerator/ClassType.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ public function __toString(): string
8989
try {
9090
return (new Printer)->printClass($this, $this->namespace);
9191
} catch (\Throwable $e) {
92+
if (PHP_VERSION_ID >= 70400) {
93+
throw $e;
94+
}
9295
trigger_error('Exception in ' . __METHOD__ . "(): {$e->getMessage()} in {$e->getFile()}:{$e->getLine()}", E_USER_ERROR);
9396
}
9497
}

src/PhpGenerator/Closure.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public function __toString(): string
4040
try {
4141
return (new Printer)->printClosure($this);
4242
} catch (\Throwable $e) {
43+
if (PHP_VERSION_ID >= 70400) {
44+
throw $e;
45+
}
4346
trigger_error('Exception in ' . __METHOD__ . "(): {$e->getMessage()} in {$e->getFile()}:{$e->getLine()}", E_USER_ERROR);
4447
}
4548
}

src/PhpGenerator/GlobalFunction.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ public function __toString(): string
3838
try {
3939
return (new Printer)->printFunction($this);
4040
} catch (\Throwable $e) {
41+
if (PHP_VERSION_ID >= 70400) {
42+
throw $e;
43+
}
4144
trigger_error('Exception in ' . __METHOD__ . "(): {$e->getMessage()} in {$e->getFile()}:{$e->getLine()}", E_USER_ERROR);
4245
}
4346
}

src/PhpGenerator/Method.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ public function __toString(): string
5353
try {
5454
return (new Printer)->printMethod($this);
5555
} catch (\Throwable $e) {
56+
if (PHP_VERSION_ID >= 70400) {
57+
throw $e;
58+
}
5659
trigger_error('Exception in ' . __METHOD__ . "(): {$e->getMessage()} in {$e->getFile()}:{$e->getLine()}", E_USER_ERROR);
5760
}
5861
}

src/PhpGenerator/PhpFile.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ public function __toString(): string
109109
try {
110110
return (new Printer)->printFile($this);
111111
} catch (\Throwable $e) {
112+
if (PHP_VERSION_ID >= 70400) {
113+
throw $e;
114+
}
112115
trigger_error('Exception in ' . __METHOD__ . "(): {$e->getMessage()} in {$e->getFile()}:{$e->getLine()}", E_USER_ERROR);
113116
}
114117
}

src/PhpGenerator/PhpNamespace.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ public function __toString(): string
193193
try {
194194
return (new Printer)->printNamespace($this);
195195
} catch (\Throwable $e) {
196+
if (PHP_VERSION_ID >= 70400) {
197+
throw $e;
198+
}
196199
trigger_error('Exception in ' . __METHOD__ . "(): {$e->getMessage()} in {$e->getFile()}:{$e->getLine()}", E_USER_ERROR);
197200
}
198201
}

0 commit comments

Comments
 (0)