| 1 | <?php |
||
| 21 | class EmailAddress |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * @var string |
||
| 25 | */ |
||
| 26 | private $email; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var string|null |
||
| 30 | */ |
||
| 31 | private $name; |
||
| 32 | |||
| 33 | public function __construct(string $email, string $name = null) |
||
| 38 | |||
| 39 | public function getEmail(): string |
||
| 43 | |||
| 44 | public function getName(): ?string |
||
| 48 | |||
| 49 | public function __toString(): string |
||
| 57 | } |
||
| 58 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: