3v4l.org

run code in 300+ PHP versions simultaneously
<?php class PilotId { protected $pid; /** * @param PilotId|string $pid */ public function __construct($pid){ $this->pid = (string)$pid; if(!preg_match("/^(AFA|PAY)([0-9]{4})$/", $this->pid)) throw new \InvalidArgumentException('Invalid PID'); } function __toString(){ return $this->pid; } } echo new PilotId("AFA1111") . "\n"; echo new PilotId(new PilotId("AFA1111")) . "\n"; var_dump( (string)(new PilotId("PAY9999")) == (string)(new PilotId("PAY9999")) );

preferences:
38.37 ms | 402 KiB | 5 Q