From 94971697597f6bdef92fb3066f42bb7e49e0c51c Mon Sep 17 00:00:00 2001 From: Pierre-Henry Soria Date: Sun, 3 Sep 2023 11:03:00 +1000 Subject: [PATCH] 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 :) --- src/Dal/UserDal.php | 4 ++-- src/Service/User.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Dal/UserDal.php b/src/Dal/UserDal.php index 17e2871..e8949f2 100644 --- a/src/Dal/UserDal.php +++ b/src/Dal/UserDal.php @@ -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(); @@ -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(); diff --git a/src/Service/User.php b/src/Service/User.php index 84caa17..3e2a974 100644 --- a/src/Service/User.php +++ b/src/Service/User.php @@ -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'); }