Created
December 6, 2023 13:57
-
-
Save tsh-code/0137a2d8177e4c75d8e0bb4190b59666 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 1. | |
$isUserModerator = $user->isType(‘moderator’); | |
class User { | |
// . . . | |
public function isType(string $type): bool | |
{ | |
return $this->type === $type; | |
} | |
// . . . | |
} | |
// 2. | |
$isUserModerator = $user->isModerator(); | |
class User { | |
// . . . | |
function isModerator(): bool | |
{ | |
return ‘moderator’ === $user->type; | |
} | |
// . . . | |
} | |
// 3. | |
$isUserModerator = $user->isType(User::TYPE_MODERATOR); | |
class User { | |
public const TYPE_MODERATOR = ‘moderator’; | |
// . . . | |
public function isType(string $type): bool | |
{ | |
return $this->type === $type; | |
} | |
// . . . | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment