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 = (float) $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], $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/jMcdT on line 55 string(28) "foo_1392275190.0036_b09a0340" string(28) "foo_1392275190.0036_b09a0340"
Output for 7.0.14
Warning: assert(): assert($one->equals($two)) failed in /in/jMcdT on line 55 string(28) "foo_1392275190.0039_6f1bcf15" string(28) "foo_1392275190.0039_6f1bcf15"
Output for 7.0.6
Warning: assert(): assert($one->equals($two)) failed in /in/jMcdT on line 55 string(28) "foo_1462233633.0989_e7e6601f" string(28) "foo_1462233633.0989_e7e6601f"
Output for 7.0.5
Warning: assert(): assert($one->equals($two)) failed in /in/jMcdT on line 55 string(28) "foo_1459603061.3642_6a4d133b" string(28) "foo_1459603061.3642_6a4d133b"
Output for 7.0.4
Warning: assert(): assert($one->equals($two)) failed in /in/jMcdT on line 55 string(27) "foo_1457567060.243_64be941d" string(27) "foo_1457567060.243_64be941d"
Output for 7.0.3
Warning: assert(): assert($one->equals($two)) failed in /in/jMcdT on line 55 string(28) "foo_1458258996.7241_b13b6ca9" string(28) "foo_1458258996.7241_b13b6ca9"
Output for 7.0.2
Warning: assert(): assert($one->equals($two)) failed in /in/jMcdT on line 55 string(28) "foo_1458556323.3623_e8936ea3" string(28) "foo_1458556323.3623_e8936ea3"
Output for 7.0.1
Warning: assert(): assert($one->equals($two)) failed in /in/jMcdT on line 55 string(28) "foo_1458729812.4958_e5f233d5" string(28) "foo_1458729812.4958_e5f233d5"
Output for 7.0.0
Warning: assert(): assert($one->equals($two)) failed in /in/jMcdT on line 55 string(28) "foo_1458998150.2123_25bf9088" string(28) "foo_1458998150.2123_25bf9088"
Output for hhvm-3.12.0
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1457669577.7679_1c13417d" string(28) "foo_1457669577.7679_1c13417d"
Output for hhvm-3.10.0
string(28) "foo_1459271221.2919_b44c21e6" string(28) "foo_1459271221.2919_b44c21e6"
Output for 5.6.28
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1392275190.0045_f0a11cdc" string(28) "foo_1392275190.0045_f0a11cdc"
Output for 5.6.21
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1462129467.0267_8c1473ac" string(28) "foo_1462129467.0267_8c1473ac"
Output for 5.6.20
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1460190756.9833_90dce8d7" string(28) "foo_1460190756.9833_90dce8d7"
Output for 5.6.19
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1457301245.0212_fec240b9" string(28) "foo_1457301245.0212_fec240b9"
Output for 5.6.18
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(27) "foo_1457947359.146_e04bd838" string(27) "foo_1457947359.146_e04bd838"
Output for 5.6.17
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1458361548.1778_48239ccc" string(28) "foo_1458361548.1778_48239ccc"
Output for 5.6.16
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1459087173.5583_e891cce1" string(28) "foo_1459087173.5583_e891cce1"
Output for 5.6.15
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1459176828.3802_bef5b2a8" string(28) "foo_1459176828.3802_bef5b2a8"
Output for 5.6.14
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(27) "foo_1459532002.827_6b232bc4" string(27) "foo_1459532002.827_6b232bc4"
Output for 5.6.13
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1460668872.9249_783a618f" string(28) "foo_1460668872.9249_783a618f"
Output for 5.6.12
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1461061737.3457_1134a3a1" string(28) "foo_1461061737.3457_1134a3a1"
Output for 5.6.11
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1461347109.6783_67c20f69" string(28) "foo_1461347109.6783_67c20f69"
Output for 5.6.10
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1461525907.3115_42801205" string(28) "foo_1461525907.3115_42801205"
Output for 5.6.9
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1461717229.5074_40ee1a87" string(28) "foo_1461717229.5074_40ee1a87"
Output for 5.6.8
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1461917335.9763_712ac6ed" string(28) "foo_1461917335.9763_712ac6ed"
Output for 5.6.7
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1464115772.1787_770e5538" string(28) "foo_1464115772.1787_770e5538"
Output for 5.5.35
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1463869271.6445_6bc00fcb" string(28) "foo_1463869271.6445_6bc00fcb"
Output for 5.5.34
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1460298479.6339_a681d798" string(28) "foo_1460298479.6339_a681d798"
Output for 5.5.33
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1457433537.8468_79e2ff7f" string(28) "foo_1457433537.8468_79e2ff7f"
Output for 5.5.32
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1458145141.3017_abdf22a7" string(28) "foo_1458145141.3017_abdf22a7"
Output for 5.5.31
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1458458338.2408_0b7e5d4c" string(28) "foo_1458458338.2408_0b7e5d4c"
Output for 5.5.30
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(27) "foo_1459443357.668_53594f2f" string(27) "foo_1459443357.668_53594f2f"
Output for 5.5.29
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1460806039.9515_057666c6" string(28) "foo_1460806039.9515_057666c6"
Output for 5.5.28
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1461159764.3145_be3b5548" string(28) "foo_1461159764.3145_be3b5548"
Output for 5.5.27
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1461255422.9856_4c5e5613" string(28) "foo_1461255422.9856_4c5e5613"
Output for 5.5.26
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1461620539.8378_4f8d4a94" string(28) "foo_1461620539.8378_4f8d4a94"
Output for 5.5.25
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(27) "foo_1461815413.495_e6d2d9b1" string(27) "foo_1461815413.495_e6d2d9b1"
Output for 5.5.24
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1462015363.9783_24784b44" string(28) "foo_1462015363.9783_24784b44"
Output for 5.4.45
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1442172316.1632_9bb3ddc1" string(28) "foo_1442172316.1632_9bb3ddc1"
Output for 5.4.44
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1439680536.3004_7ac45c0d" string(28) "foo_1439680536.3004_7ac45c0d"
Output for 5.4.43
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1439680531.8598_479ccb4b" string(28) "foo_1439680531.8598_479ccb4b"
Output for 5.4.42
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1439680530.4766_8ed9705f" string(28) "foo_1439680530.4766_8ed9705f"
Output for 5.4.41
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1439680528.2156_280982e9" string(28) "foo_1439680528.2156_280982e9"
Output for 5.4.40
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1431065408.9716_aa965640" string(28) "foo_1431065408.9716_aa965640"
Output for 5.4.39
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1431065408.1821_149aa0b7" string(28) "foo_1431065408.1821_149aa0b7"
Output for 5.4.38
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1425280155.6079_7fc2630e" string(28) "foo_1425280155.6079_7fc2630e"
Output for 5.4.37
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1423359912.5301_da6aabd3" string(28) "foo_1423359912.5301_da6aabd3"
Output for 5.4.36
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1423359912.1627_28e17472" string(28) "foo_1423359912.1627_28e17472"
Output for 5.4.35
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1417713115.5731_4a16b75e" string(28) "foo_1417713115.5731_4a16b75e"
Output for 5.4.34
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1417713115.2711_37d38f0e" string(28) "foo_1417713115.2711_37d38f0e"
Output for 5.4.32
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1409986327.4531_68371fe6" string(28) "foo_1409986327.4531_68371fe6"
Output for 5.4.31
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1409986324.1043_529d2bf9" string(28) "foo_1409986324.1043_529d2bf9"
Output for 5.4.30
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1409986320.3942_c77c5c07" string(28) "foo_1409986320.3942_c77c5c07"
Output for 5.4.29
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(27) "foo_1409986320.067_075c18bc" string(27) "foo_1409986320.067_075c18bc"
Output for 5.4.28
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(27) "foo_1409986319.737_09db8e9b" string(27) "foo_1409986319.737_09db8e9b"
Output for 5.4.27
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1409986325.3262_3cf8581c" string(28) "foo_1409986325.3262_3cf8581c"
Output for 5.4.26
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1409986325.0171_ff16ff1f" string(28) "foo_1409986325.0171_ff16ff1f"
Output for 5.4.25
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(27) "foo_1392275191.664_3e34a1b2" string(27) "foo_1392275191.664_3e34a1b2"
Output for 5.4.24
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1392275191.7082_b6b8dffa" string(28) "foo_1392275191.7082_b6b8dffa"
Output for 5.4.23
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1392275191.7534_91d210a3" string(28) "foo_1392275191.7534_91d210a3"
Output for 5.4.22
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1392275191.7973_b28a8ff5" string(28) "foo_1392275191.7973_b28a8ff5"
Output for 5.4.21
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1392275191.8426_facdb19c" string(28) "foo_1392275191.8426_facdb19c"
Output for 5.4.20
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1392275191.8897_1b507434" string(28) "foo_1392275191.8897_1b507434"
Output for 5.4.19
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(27) "foo_1392275191.939_e27c872e" string(27) "foo_1392275191.939_e27c872e"
Output for 5.4.18
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1392275191.9847_1602ddee" string(28) "foo_1392275191.9847_1602ddee"
Output for 5.4.17
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1392275192.0306_b30c19c2" string(28) "foo_1392275192.0306_b30c19c2"
Output for 5.4.16
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1392275192.0746_007550b4" string(28) "foo_1392275192.0746_007550b4"
Output for 5.4.15
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1392275192.1276_c301143f" string(28) "foo_1392275192.1276_c301143f"
Output for 5.4.14
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1392275192.1793_b29b9baf" string(28) "foo_1392275192.1793_b29b9baf"
Output for 5.4.13
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1392275192.2252_0638a11e" string(28) "foo_1392275192.2252_0638a11e"
Output for 5.4.12
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1392275192.2713_7f5085b1" string(28) "foo_1392275192.2713_7f5085b1"
Output for 5.4.11
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(27) "foo_1392275192.334_3cde12eb" string(27) "foo_1392275192.334_3cde12eb"
Output for 5.4.10
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1392275192.3822_59790748" string(28) "foo_1392275192.3822_59790748"
Output for 5.4.9
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1392275192.4262_135d5d5f" string(28) "foo_1392275192.4262_135d5d5f"
Output for 5.4.8
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1392275192.4747_a8caf028" string(28) "foo_1392275192.4747_a8caf028"
Output for 5.4.7
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1392275192.5189_cd4dfcf9" string(28) "foo_1392275192.5189_cd4dfcf9"
Output for 5.4.6
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1392275192.5693_9bbe33e9" string(28) "foo_1392275192.5693_9bbe33e9"
Output for 5.4.5
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1392275192.6131_fec74565" string(28) "foo_1392275192.6131_fec74565"
Output for 5.4.4
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1392275192.6564_8b6a1ec8" string(28) "foo_1392275192.6564_8b6a1ec8"
Output for 5.4.3
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1392275192.6996_0d8e34c5" string(28) "foo_1392275192.6996_0d8e34c5"
Output for 5.4.2
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1392275192.7471_c255857f" string(28) "foo_1392275192.7471_c255857f"
Output for 5.4.1
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(27) "foo_1392275192.792_e5e5a67e" string(27) "foo_1392275192.792_e5e5a67e"
Output for 5.4.0
Warning: assert(): Assertion failed in /in/jMcdT on line 55 string(28) "foo_1392275192.8355_4156f69b" string(28) "foo_1392275192.8355_4156f69b"
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/jMcdT on line 49
Process exited with code 255.
Output for 5.1.0 - 5.2.17
Parse error: syntax error, unexpected ':' in /in/jMcdT on line 11
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected ':' in /in/jMcdT 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/jMcdT 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/jMcdT on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/jMcdT on line 3
Process exited with code 255.