Skip to content

Commit

Permalink
Hello my Udemy fellows, with PHP 8.0, you can now omit the caught var…
Browse files Browse the repository at this point in the history
…iable 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 :)
  • Loading branch information
pH-7 committed Sep 3, 2023
1 parent 0b3d504 commit 9497169
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Dal/UserDal.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static function create(UserEntity $userEntity): string|false

try {
$redBeanIncrementId = R::store($userBean);
} catch (SQL $e) {
} catch (SQL) { // since PHP 8, we can omit the caught variable (e.g. SQL $e)
return false;
} finally {
R::close();
Expand Down Expand Up @@ -68,7 +68,7 @@ public static function update(string $userUuid, UserEntity $userEntity): int|str
// attempt to save the user
try {
return R::store($userBean); // returns the user ID
} catch (SQL $e) {
} catch (SQL) { // PHP >=8.0 allows to omit the caught variable (e.g. SQL $e)
return false;
} finally {
R::close();
Expand Down
2 changes: 1 addition & 1 deletion src/Service/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function login(mixed $data): array

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

Expand Down

0 comments on commit 9497169

Please sign in to comment.