3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class MessageId { protected static $partSeperator = '_'; protected static $hashAlgorithm = 'crc32'; protected static $validNames = ['foo']; 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); } } $foo = new MessageId('foo'); var_dump((string) $foo);
Output for 7.1.0
string(28) "foo_1392338305.0058_ccd152c2"
Output for 7.0.14
string(28) "foo_1392338305.0039_54afed7e"
Output for 7.0.6
string(28) "foo_1462292180.4406_f1f038ca"
Output for 7.0.5
string(28) "foo_1459658542.5234_1d5da8d3"
Output for 7.0.4
string(28) "foo_1457630902.5953_4734d654"
Output for 7.0.3
string(27) "foo_1458326108.341_b81cbc3d"
Output for 7.0.2
string(28) "foo_1458693772.7293_bd18afbb"
Output for 7.0.1
string(28) "foo_1458793442.3901_81485ba5"
Output for 7.0.0
string(28) "foo_1459056024.0832_27331418"
Output for hhvm-3.12.0
string(27) "foo_1457858437.141_0966845b"
Output for hhvm-3.10.0
string(28) "foo_1459380572.5815_9f4d9a5b"
Output for 5.6.28
string(28) "foo_1392338305.0045_fc47d605"
Output for 5.6.21
string(28) "foo_1462188360.6322_0869fe04"
Output for 5.6.20
string(28) "foo_1460259700.8847_3d93dbb2"
Output for 5.6.19
string(28) "foo_1457401152.7942_d08853c1"
Output for 5.6.18
string(28) "foo_1458037333.5932_05f9a9f6"
Output for 5.6.17
string(28) "foo_1458424915.5452_727ed5d2"
Output for 5.6.16
string(28) "foo_1459145266.7244_488d9a2d"
Output for 5.6.15
string(28) "foo_1459234693.4756_5005efd7"
Output for 5.6.14
string(28) "foo_1459587013.7876_813ca574"
Output for 5.6.13
string(28) "foo_1460725993.8993_67c37234"
Output for 5.6.12
string(28) "foo_1461123728.4172_6f3bfef3"
Output for 5.6.11
string(28) "foo_1461491887.3038_8661053d"
Output for 5.6.10
string(28) "foo_1461586042.7287_9ebed5c9"
Output for 5.6.9
string(28) "foo_1461777436.6638_5c8fd297"
Output for 5.6.8
string(28) "foo_1461982211.7296_0eaffe13"
Output for 5.5.35
string(28) "foo_1463940473.0699_bb64f0ec"
Output for 5.5.34
string(28) "foo_1460354003.2342_28afbc63"
Output for 5.5.33
string(28) "foo_1457497214.1134_5eb5ae6f"
Output for 5.5.32
string(28) "foo_1458224182.5324_4bf8778e"
Output for 5.5.31
string(28) "foo_1458522161.5022_3a3dfa23"
Output for 5.5.30
string(28) "foo_1459500721.2825_40ed26f1"
Output for 5.5.29
string(28) "foo_1460864218.2436_a382c838"
Output for 5.5.28
string(28) "foo_1461221736.7963_d065958f"
Output for 5.5.27
string(28) "foo_1461314583.0755_33e13074"
Output for 5.5.26
string(27) "foo_1461682221.509_73096c80"
Output for 5.5.25
string(28) "foo_1461879733.0773_5bb52d3b"
Output for 5.5.24
string(28) "foo_1464063354.6814_740cccc5"
Output for 5.4.45
string(28) "foo_1446633354.7515_68021009"
Output for 5.4.44
string(28) "foo_1446633355.1683_26db1b91"
Output for 5.4.43
string(28) "foo_1446633355.5844_875e07f4"
Output for 5.4.42
string(28) "foo_1446633356.0671_a0828e1c"
Output for 5.4.41
string(28) "foo_1446633356.4818_4d82f993"
Output for 5.4.40
string(28) "foo_1446633356.8921_92177602"
Output for 5.4.39
string(28) "foo_1446633357.3055_b29edcdd"
Output for 5.4.38
string(28) "foo_1446633357.8006_3ab390dc"
Output for 5.4.37
string(28) "foo_1446633358.2044_9a3c92bb"
Output for 5.4.36
string(28) "foo_1446633358.6409_12e4b240"
Output for 5.4.35
string(28) "foo_1446633359.0597_6e4a4d27"
Output for 5.4.34
string(28) "foo_1446633359.4762_e474362d"
Output for 5.4.32
string(28) "foo_1446633359.8944_cb151652"
Output for 5.4.31
string(28) "foo_1446633360.3312_ad496e78"
Output for 5.4.30
string(26) "foo_1446633360.75_13ae9fc6"
Output for 5.4.29
string(28) "foo_1446633361.1544_aefa03d1"
Output for 5.4.28
string(28) "foo_1446633361.5674_6e3b91f2"
Output for 5.4.27
string(28) "foo_1446633361.9892_f49a5732"
Output for 5.4.26
string(28) "foo_1446633362.4128_9b800dca"
Output for 5.4.25
string(28) "foo_1446633362.8403_306afe35"
Output for 5.4.24
string(28) "foo_1446633363.3211_d598050f"
Output for 5.4.23
string(28) "foo_1446633363.7253_b2829c62"
Output for 5.4.22
string(28) "foo_1446633364.1684_49dfff0c"
Output for 5.4.21
string(28) "foo_1446633364.5631_5d310946"
Output for 5.4.20
string(28) "foo_1446633364.9417_ff0b0a38"
Output for 5.4.19
string(28) "foo_1446633365.3718_2a6b427c"
Output for 5.4.18
string(28) "foo_1446633365.7705_650a20ff"
Output for 5.4.17
string(28) "foo_1446633366.1459_80af0c6a"
Output for 5.4.16
string(28) "foo_1446633366.6587_fe012a96"
Output for 5.4.15
string(28) "foo_1446633367.0527_4346a597"
Output for 5.4.14
string(28) "foo_1446633367.3987_180c8d6d"
Output for 5.4.13
string(28) "foo_1446633367.9066_c26e80af"
Output for 5.4.12
string(28) "foo_1446633368.3021_f1bb5df4"
Output for 5.4.11
string(28) "foo_1446633368.6971_47e90033"
Output for 5.4.10
string(28) "foo_1446633369.1492_1c913ab6"
Output for 5.4.9
string(28) "foo_1446633369.5661_376e9b07"
Output for 5.4.8
string(28) "foo_1446633369.9864_c53e6964"
Output for 5.4.7
string(28) "foo_1446633370.4383_71705cac"
Output for 5.4.6
string(27) "foo_1446633370.831_fdb96452"
Output for 5.4.5
string(27) "foo_1446633371.247_630b39f5"
Output for 5.4.4
string(28) "foo_1446633371.6588_5b317161"
Output for 5.4.3
string(28) "foo_1446633372.0723_7c104ece"
Output for 5.4.2
string(28) "foo_1446633372.4877_58a8158e"
Output for 5.4.1
string(28) "foo_1446633372.9402_8cc345e9"
Output for 5.4.0
string(28) "foo_1446633373.3611_152297a5"
Output for 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/TZvOX on line 7
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/TZvOX 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/TZvOX 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/TZvOX 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/TZvOX on line 5
Process exited with code 255.