units = $value; } } public function __construct(int $units) { $this->units = $units; } } $quantity = new Quantity(3); try { $quantity->units = -1; } catch (InvalidArgumentException $error) { echo $error->getMessage(), PHP_EOL; } echo $quantity->units, PHP_EOL; // 3 try { new Quantity(-1); throw new RuntimeException('Invalid construction was accepted'); } catch (InvalidArgumentException) { echo "Invalid construction rejected", PHP_EOL; } $quantity->units = 5; echo $quantity->units, PHP_EOL;