Skip to content

Commit 9497169

Browse files
committed
Hello my Udemy fellows, with PHP 8.0, you can now omit the caught variable name in your catch block`
if you don't need to access to the thrown object inside of the block This way, we don't need to mention an unused variable in our definition :)
1 parent 0b3d504 commit 9497169

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/Dal/UserDal.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static function create(UserEntity $userEntity): string|false
3030

3131
try {
3232
$redBeanIncrementId = R::store($userBean);
33-
} catch (SQL $e) {
33+
} catch (SQL) { // since PHP 8, we can omit the caught variable (e.g. SQL $e)
3434
return false;
3535
} finally {
3636
R::close();
@@ -68,7 +68,7 @@ public static function update(string $userUuid, UserEntity $userEntity): int|str
6868
// attempt to save the user
6969
try {
7070
return R::store($userBean); // returns the user ID
71-
} catch (SQL $e) {
71+
} catch (SQL) { // PHP >=8.0 allows to omit the caught variable (e.g. SQL $e)
7272
return false;
7373
} finally {
7474
R::close();

src/Service/User.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function login(mixed $data): array
5959

6060
try {
6161
UserDal::setToken($jwtToken, $user->getUserUuid());
62-
} catch (Exception $e) {
62+
} catch (Exception) { // since PHP 8.0, we can omit the caught variable name (e.g. Exception $e)
6363
throw new CannotLoginUserException('Cannot set token to user');
6464
}
6565

0 commit comments

Comments
 (0)