$mailbox; private $host; public function __construct(string $email) { if (false === strpos($email, '@')) { throw new \InvalidArgumentException( 'This does not look like an email!'); } list($this->mailbox, $this->host) = explode('@', $email); } public function __toString() { return sprintf('%s@%s', $this->mailbox, $this->host); } }
/** * @return int * @throws InvalidArgumentException */ public function getAge() { if (!isset($this->birthday)) { throw new InvalidArgumentException('...'); } // Calculate and return $age ... } public function hasBirthday() { return isset($this->birthday); } }
getAmount(); } final class HeavyUserDiscount implements Amountable { public function getAmount() { $amount = 0.00; // ... return new Money($amount); } }
public function __clone() { throw new LogicException( 'Why would you even clone me?'); } public function __sleep() { throw new BadMethodCallException( 'Serialize, really?'); } }