3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Email implements JsonSerializable { private $value; public function __construct(string $value) { $email = filter_var($value, FILTER_VALIDATE_EMAIL); if (false === $email) { throw new Exception('Email is invalid.'); } $this->value = $email; } public function jsonSerialize() { return $this->value; } } $email = new Email('opexus@gmail'); echo json_encode(compact('email'));

preferences:
46.26 ms | 402 KiB | 5 Q