3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php final class CommandId { private $name; private $time; private $hash; public function __construct($name, $time = null, $hash = null) { $this->time = $time ?: microtime(true); $this->name = trim($name); $this->hash = $hash ?: hash('crc32', rand(0, $this->time)); if (empty($this->name)) { throw new DomainException('Name must not be empty'); } } public static function fromString($idString) { $parts = explode('_', $idString); if (count($parts) != 3) { throw new DomainException("Unexpected format [$idString]"); } return new static($parts[0], (float) $parts[1], $parts[2]); } public function name() { return $this->name; } public function time() { return $this->time; } public function equals(self $other) { return ( $this->name == $other->name && $this->time == $other->time && $this->hash == $other->hash ); } public function __toString() { return implode('_', [$this->name, $this->time, $this->hash]); } } $one = new CommandId('foo'); $two = CommandId::fromString((string) $one); assert($one->equals($two)); var_dump((string) $one, (string) $two);
Output for 7.1.0
Warning: assert(): assert($one->equals($two)) failed in /in/1Q7Ss on line 56 string(28) "foo_1392274887.0059_89962a53" string(28) "foo_1392274887.0059_89962a53"
Output for 7.0.14
Warning: assert(): assert($one->equals($two)) failed in /in/1Q7Ss on line 56 string(28) "foo_1392274887.0038_af930e7d" string(28) "foo_1392274887.0038_af930e7d"
Output for 7.0.6
string(28) "foo_1462292940.6645_2e7201d7" string(28) "foo_1462292940.6645_2e7201d7"
Output for 7.0.5
Warning: assert(): assert($one->equals($two)) failed in /in/1Q7Ss on line 56 string(28) "foo_1459659254.5733_756b497a" string(28) "foo_1459659254.5733_756b497a"
Output for 7.0.4
Warning: assert(): assert($one->equals($two)) failed in /in/1Q7Ss on line 56 string(28) "foo_1457631661.5314_9f8b7706" string(28) "foo_1457631661.5314_9f8b7706"
Output for 7.0.3
Warning: assert(): assert($one->equals($two)) failed in /in/1Q7Ss on line 56 string(28) "foo_1458326972.8255_b293a994" string(28) "foo_1458326972.8255_b293a994"
Output for 7.0.2
Warning: assert(): assert($one->equals($two)) failed in /in/1Q7Ss on line 56 string(28) "foo_1458694617.5664_240c75f7" string(28) "foo_1458694617.5664_240c75f7"
Output for 7.0.1
Warning: assert(): assert($one->equals($two)) failed in /in/1Q7Ss on line 56 string(28) "foo_1458794190.1568_73c2371e" string(28) "foo_1458794190.1568_73c2371e"
Output for 7.0.0
Warning: assert(): assert($one->equals($two)) failed in /in/1Q7Ss on line 56 string(28) "foo_1459056759.3358_47ae8a54" string(28) "foo_1459056759.3358_47ae8a54"
Output for 5.6.28
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1392274887.0047_1097464c" string(28) "foo_1392274887.0047_1097464c"
Output for 5.6.21
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1462189094.2522_baf02c87" string(28) "foo_1462189094.2522_baf02c87"
Output for 5.6.20
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1460260412.6845_c3272d80" string(28) "foo_1460260412.6845_c3272d80"
Output for 5.6.19
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1457401949.4002_c4ec1c37" string(28) "foo_1457401949.4002_c4ec1c37"
Output for 5.6.18
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1458038143.6066_23298bc5" string(28) "foo_1458038143.6066_23298bc5"
Output for 5.6.17
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1458425719.1039_f548c4a0" string(28) "foo_1458425719.1039_f548c4a0"
Output for 5.6.16
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1459145999.3509_c7e954ac" string(28) "foo_1459145999.3509_c7e954ac"
Output for 5.6.15
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1459235437.8004_1ac68873" string(28) "foo_1459235437.8004_1ac68873"
Output for 5.6.14
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1459587703.5144_1676435c" string(28) "foo_1459587703.5144_1676435c"
Output for 5.6.13
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1460726762.5724_3704c031" string(28) "foo_1460726762.5724_3704c031"
Output for 5.6.12
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1461124510.5318_0a628d7a" string(28) "foo_1461124510.5318_0a628d7a"
Output for 5.6.11
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1461493062.8279_1676c636" string(28) "foo_1461493062.8279_1676c636"
Output for 5.6.10
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1461586828.6836_63596999" string(28) "foo_1461586828.6836_63596999"
Output for 5.6.9
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1461778235.2624_e9303f00" string(28) "foo_1461778235.2624_e9303f00"
Output for 5.6.8
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1461982965.2735_8f20032c" string(28) "foo_1461982965.2735_8f20032c"
Output for 5.5.35
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1463942967.9414_eba1ec6e" string(28) "foo_1463942967.9414_eba1ec6e"
Output for 5.5.34
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1460354728.6827_25d7ee20" string(28) "foo_1460354728.6827_25d7ee20"
Output for 5.5.33
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1457498137.4039_ea8a92f8" string(28) "foo_1457498137.4039_ea8a92f8"
Output for 5.5.32
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1458225066.0522_71ab52f4" string(28) "foo_1458225066.0522_71ab52f4"
Output for 5.5.31
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1458523034.9649_853c15d3" string(28) "foo_1458523034.9649_853c15d3"
Output for 5.5.30
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1459501463.4617_76ca1d9a" string(28) "foo_1459501463.4617_76ca1d9a"
Output for 5.5.29
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1460864955.6352_08077d1c" string(28) "foo_1460864955.6352_08077d1c"
Output for 5.5.28
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(27) "foo_1461222545.912_ecab7259" string(27) "foo_1461222545.912_ecab7259"
Output for 5.5.27
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1461315333.5952_1b045eaf" string(28) "foo_1461315333.5952_1b045eaf"
Output for 5.5.26
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1461683009.9886_6992ba2f" string(28) "foo_1461683009.9886_6992ba2f"
Output for 5.5.25
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1461880554.6018_48c838f7" string(28) "foo_1461880554.6018_48c838f7"
Output for 5.5.24
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1464064114.5199_35c82d34" string(28) "foo_1464064114.5199_35c82d34"
Output for 5.4.45
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1446940072.4199_5cb911ec" string(28) "foo_1446940072.4199_5cb911ec"
Output for 5.4.44
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1446940073.7338_21bbc3ea" string(28) "foo_1446940073.7338_21bbc3ea"
Output for 5.4.43
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(27) "foo_1446940075.147_0e5bf73f" string(27) "foo_1446940075.147_0e5bf73f"
Output for 5.4.42
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1446940075.9118_6e620d60" string(28) "foo_1446940075.9118_6e620d60"
Output for 5.4.41
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1446940076.2728_50c95698" string(28) "foo_1446940076.2728_50c95698"
Output for 5.4.40
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1446940077.4956_74a06c03" string(28) "foo_1446940077.4956_74a06c03"
Output for 5.4.39
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1446940078.2083_7a19eb7c" string(28) "foo_1446940078.2083_7a19eb7c"
Output for 5.4.38
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1446940078.5577_bacda206" string(28) "foo_1446940078.5577_bacda206"
Output for 5.4.37
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1446940079.3926_307035a1" string(28) "foo_1446940079.3926_307035a1"
Output for 5.4.36
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1446940079.5842_b41fadaf" string(28) "foo_1446940079.5842_b41fadaf"
Output for 5.4.35
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1446940080.0655_cce6670c" string(28) "foo_1446940080.0655_cce6670c"
Output for 5.4.34
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1446940080.7787_6ec1d24c" string(28) "foo_1446940080.7787_6ec1d24c"
Output for 5.4.32
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1446940081.6421_44326cb5" string(28) "foo_1446940081.6421_44326cb5"
Output for 5.4.31
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1446940081.9086_1d99ec66" string(28) "foo_1446940081.9086_1d99ec66"
Output for 5.4.30
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(27) "foo_1446940082.413_3f6af77f" string(27) "foo_1446940082.413_3f6af77f"
Output for 5.4.29
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1446940082.5589_83003f5b" string(28) "foo_1446940082.5589_83003f5b"
Output for 5.4.28
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1446940082.8462_2166553e" string(28) "foo_1446940082.8462_2166553e"
Output for 5.4.27
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1446940083.1383_26adedbb" string(28) "foo_1446940083.1383_26adedbb"
Output for 5.4.26
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1446940083.4369_88a2b497" string(28) "foo_1446940083.4369_88a2b497"
Output for 5.4.25
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1446940083.7484_80c7c28a" string(28) "foo_1446940083.7484_80c7c28a"
Output for 5.4.24
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1446940084.2062_a878c121" string(28) "foo_1446940084.2062_a878c121"
Output for 5.4.23
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1446940084.3454_cb44b380" string(28) "foo_1446940084.3454_cb44b380"
Output for 5.4.22
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1446940084.8905_3ecd480b" string(28) "foo_1446940084.8905_3ecd480b"
Output for 5.4.21
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1446940085.0402_334d2fd0" string(28) "foo_1446940085.0402_334d2fd0"
Output for 5.4.20
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1446940085.3521_9a9e2fb7" string(28) "foo_1446940085.3521_9a9e2fb7"
Output for 5.4.19
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1446940085.7696_b55cba93" string(28) "foo_1446940085.7696_b55cba93"
Output for 5.4.18
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1446940086.0596_6157493a" string(28) "foo_1446940086.0596_6157493a"
Output for 5.4.17
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(26) "foo_1446940086.46_f3acda9c" string(26) "foo_1446940086.46_f3acda9c"
Output for 5.4.16
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1446940086.7269_4a2338cd" string(28) "foo_1446940086.7269_4a2338cd"
Output for 5.4.15
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1446940086.9989_5484e6b5" string(28) "foo_1446940086.9989_5484e6b5"
Output for 5.4.14
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1446940087.2408_cc2731d0" string(28) "foo_1446940087.2408_cc2731d0"
Output for 5.4.13
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1446940087.5146_b19bb7c4" string(28) "foo_1446940087.5146_b19bb7c4"
Output for 5.4.12
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(27) "foo_1446940087.774_7267746a" string(27) "foo_1446940087.774_7267746a"
Output for 5.4.11
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1446940088.2312_27b2af8f" string(28) "foo_1446940088.2312_27b2af8f"
Output for 5.4.10
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1446940088.5594_d318e5a8" string(28) "foo_1446940088.5594_d318e5a8"
Output for 5.4.9
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1446940088.7384_18a0f13c" string(28) "foo_1446940088.7384_18a0f13c"
Output for 5.4.8
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1446940089.1457_760213f0" string(28) "foo_1446940089.1457_760213f0"
Output for 5.4.7
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(27) "foo_1446940089.494_f36eb4db" string(27) "foo_1446940089.494_f36eb4db"
Output for 5.4.6
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1446940089.6682_1fcd8ae1" string(28) "foo_1446940089.6682_1fcd8ae1"
Output for 5.4.5
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1446940090.1267_71a1277c" string(28) "foo_1446940090.1267_71a1277c"
Output for 5.4.4
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1446940090.4472_178c46fb" string(28) "foo_1446940090.4472_178c46fb"
Output for 5.4.3
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1446940090.6218_d917f1fd" string(28) "foo_1446940090.6218_d917f1fd"
Output for 5.4.2
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1446940091.0793_f5fffb12" string(28) "foo_1446940091.0793_f5fffb12"
Output for 5.4.1
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(28) "foo_1446940091.3817_5483db7f" string(28) "foo_1446940091.3817_5483db7f"
Output for 5.4.0
Warning: assert(): Assertion failed in /in/1Q7Ss on line 56 string(27) "foo_1446940091.569_d383f2cf" string(27) "foo_1446940091.569_d383f2cf"
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/1Q7Ss on line 50
Process exited with code 255.
Output for 5.1.0 - 5.2.17
Parse error: syntax error, unexpected ':' in /in/1Q7Ss on line 11
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected ':' in /in/1Q7Ss on line 11
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_CLASS in /in/1Q7Ss on line 3
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_CLASS in /in/1Q7Ss on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/1Q7Ss on line 3
Process exited with code 255.