3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class MessageId { protected static $partSeperator = '_'; protected static $hashAlgorithm = 'crc32'; protected static $validNames = []; protected $name; protected $time; protected $hash; public function __construct($name) { $this->time = microtime(true); $this->name = trim($name); $this->hash = hash(static::$hashAlgorithm, rand(0, $this->time)); if (empty($this->name)) { throw new DomainException('Name must not be empty'); } if (!in_array($this->name, static::$validNames)) { throw new DomainException("Invalid name [$name]"); } } public static function fromString($idString) { $parts = explode(static::$partSeperator, $idString); if (count($parts) != 3) { throw new DomainException("Unexpected format [$idString]"); } return static::fromParts($parts[0], $parts[1], $parts[2]); } public static function fromParts($name, $time, $hash) { $id = new static($name); $id->time = floatval($time); $id->hash = strval($hash); return $id; } public function name() { return $this->name; } public function time() { return $this->time; } public function equals(self $other) { return ((string) $this == (string) $other); } public function __toString() { return implode(static::$partSeperator, (array) $this); } } var_dump(new MessageId('foo'));
Output for 7.0.0 - 7.1.0
Fatal error: Uncaught DomainException: Invalid name [foo] in /in/oREHV:22 Stack trace: #0 /in/oREHV(65): MessageId->__construct('foo') #1 {main} thrown in /in/oREHV on line 22
Process exited with code 255.
Output for 5.4.0 - 5.6.28
Fatal error: Uncaught exception 'DomainException' with message 'Invalid name [foo]' in /in/oREHV:22 Stack trace: #0 /in/oREHV(65): MessageId->__construct('foo') #1 {main} thrown in /in/oREHV on line 22
Process exited with code 255.
Output for 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/oREHV on line 7
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/oREHV on line 7
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/oREHV on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/oREHV on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/oREHV on line 5
Process exited with code 255.