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); var_dump((string) $one, (string) $two, $one == $two);
Output for 7.1.0
string(28) "foo_1392275525.0037_29c7e2d9" string(28) "foo_1392275525.0037_29c7e2d9" bool(false)
Output for 7.0.14
string(27) "foo_1392275525.004_eb2f1f78" string(27) "foo_1392275525.004_eb2f1f78" bool(false)
Output for 7.0.6
string(28) "foo_1462233633.6341_6bb5e461" string(28) "foo_1462233633.6341_6bb5e461" bool(false)
Output for 7.0.5
string(28) "foo_1459603062.0299_24608400" string(28) "foo_1459603062.0299_24608400" bool(false)
Output for 7.0.4
string(28) "foo_1457567060.9676_ed7d9bfb" string(28) "foo_1457567060.9676_ed7d9bfb" bool(false)
Output for 7.0.3
string(28) "foo_1458258997.4427_82044cb0" string(28) "foo_1458258997.4427_82044cb0" bool(false)
Output for 7.0.2
string(28) "foo_1458556323.9727_905c4bb2" string(28) "foo_1458556323.9727_905c4bb2" bool(false)
Output for 7.0.1
string(28) "foo_1458729813.1269_965db52b" string(28) "foo_1458729813.1269_965db52b" bool(false)
Output for 7.0.0
string(28) "foo_1458998150.8422_403cf106" string(28) "foo_1458998150.8422_403cf106" bool(false)
Output for hhvm-3.12.0
string(28) "foo_1457669578.7894_f4583a9f" string(28) "foo_1457669578.7894_f4583a9f" bool(false)
Output for hhvm-3.10.0
string(28) "foo_1459271222.3001_3f6acedd" string(28) "foo_1459271222.3001_3f6acedd" bool(false)
Output for 5.6.28
string(28) "foo_1392275525.0045_2bced069" string(28) "foo_1392275525.0045_2bced069" bool(false)
Output for 5.6.21
string(28) "foo_1462129467.5252_6ff5f77a" string(28) "foo_1462129467.5252_6ff5f77a" bool(false)
Output for 5.6.20
string(28) "foo_1460190757.6416_574b94f1" string(28) "foo_1460190757.6416_574b94f1" bool(false)
Output for 5.6.19
string(28) "foo_1457301245.6402_72993390" string(28) "foo_1457301245.6402_72993390" bool(false)
Output for 5.6.18
string(28) "foo_1457947359.8369_90f17db0" string(28) "foo_1457947359.8369_90f17db0" bool(false)
Output for 5.6.17
string(28) "foo_1458361548.9862_cd1ea395" string(28) "foo_1458361548.9862_cd1ea395" bool(false)
Output for 5.6.16
string(28) "foo_1459087174.2666_391f00cf" string(28) "foo_1459087174.2666_391f00cf" bool(false)
Output for 5.6.15
string(27) "foo_1459176829.043_26817e2a" string(27) "foo_1459176829.043_26817e2a" bool(false)
Output for 5.6.14
string(28) "foo_1459532003.4995_ee9354bb" string(28) "foo_1459532003.4995_ee9354bb" bool(false)
Output for 5.6.13
string(28) "foo_1460668873.4826_297ebf45" string(28) "foo_1460668873.4826_297ebf45" bool(false)
Output for 5.6.12
string(28) "foo_1461061737.8674_d28b73a6" string(28) "foo_1461061737.8674_d28b73a6" bool(false)
Output for 5.6.11
string(28) "foo_1461347110.2445_cf9fe969" string(28) "foo_1461347110.2445_cf9fe969" bool(false)
Output for 5.6.10
string(28) "foo_1461525907.7104_501ff80b" string(28) "foo_1461525907.7104_501ff80b" bool(false)
Output for 5.6.9
string(28) "foo_1461717230.0964_ed333cae" string(28) "foo_1461717230.0964_ed333cae" bool(false)
Output for 5.6.8
string(28) "foo_1461917336.4999_43620cdc" string(28) "foo_1461917336.4999_43620cdc" bool(false)
Output for 5.6.7
string(28) "foo_1464115772.3749_297e4fde" string(28) "foo_1464115772.3749_297e4fde" bool(false)
Output for 5.5.35
string(28) "foo_1463869271.8253_8647ecd1" string(28) "foo_1463869271.8253_8647ecd1" bool(false)
Output for 5.5.34
string(28) "foo_1460298480.2737_e1f99c21" string(28) "foo_1460298480.2737_e1f99c21" bool(false)
Output for 5.5.33
string(27) "foo_1457433538.553_96a15ec9" string(27) "foo_1457433538.553_96a15ec9" bool(false)
Output for 5.5.32
string(28) "foo_1458145142.1009_ac35e8ba" string(28) "foo_1458145142.1009_ac35e8ba" bool(false)
Output for 5.5.31
string(28) "foo_1458458338.9626_3f357a8c" string(28) "foo_1458458338.9626_3f357a8c" bool(false)
Output for 5.5.30
string(28) "foo_1459443358.3507_7666bb8d" string(28) "foo_1459443358.3507_7666bb8d" bool(false)
Output for 5.5.29
string(28) "foo_1460806040.4613_be710ae7" string(28) "foo_1460806040.4613_be710ae7" bool(false)
Output for 5.5.28
string(28) "foo_1461159764.9113_ed08c1b4" string(28) "foo_1461159764.9113_ed08c1b4" bool(false)
Output for 5.5.27
string(27) "foo_1461255423.371_24688cad" string(27) "foo_1461255423.371_24688cad" bool(false)
Output for 5.5.26
string(28) "foo_1461620540.3737_d908d04e" string(28) "foo_1461620540.3737_d908d04e" bool(false)
Output for 5.5.25
string(28) "foo_1461815414.0229_522ae107" string(28) "foo_1461815414.0229_522ae107" bool(false)
Output for 5.5.24
string(28) "foo_1462015364.4652_50f175f8" string(28) "foo_1462015364.4652_50f175f8" bool(false)
Output for 5.4.45
string(27) "foo_1442172323.179_f00c2c8d" string(27) "foo_1442172323.179_f00c2c8d" bool(false)
Output for 5.4.44
string(28) "foo_1439680545.6444_326f4fd1" string(28) "foo_1439680545.6444_326f4fd1" bool(false)
Output for 5.4.43
string(28) "foo_1439680541.2537_67c956c7" string(28) "foo_1439680541.2537_67c956c7" bool(false)
Output for 5.4.42
string(28) "foo_1439680539.9187_a20345d3" string(28) "foo_1439680539.9187_a20345d3" bool(false)
Output for 5.4.41
string(28) "foo_1439680537.4882_a06c3af5" string(28) "foo_1439680537.4882_a06c3af5" bool(false)
Output for 5.4.40
string(28) "foo_1431065426.6987_b491f475" string(28) "foo_1431065426.6987_b491f475" bool(false)
Output for 5.4.39
string(27) "foo_1431065425.798_10fcb1b3" string(27) "foo_1431065425.798_10fcb1b3" bool(false)
Output for 5.4.38
string(28) "foo_1425280162.9822_0c35cc15" string(28) "foo_1425280162.9822_0c35cc15" bool(false)
Output for 5.4.37
string(28) "foo_1423359924.6564_8adcc9fa" string(28) "foo_1423359924.6564_8adcc9fa" bool(false)
Output for 5.4.36
string(28) "foo_1423359924.2852_1a35acd6" string(28) "foo_1423359924.2852_1a35acd6" bool(false)
Output for 5.4.35
string(28) "foo_1417713138.8791_12a232a0" string(28) "foo_1417713138.8791_12a232a0" bool(false)
Output for 5.4.34
string(28) "foo_1417713138.5745_6902278f" string(28) "foo_1417713138.5745_6902278f" bool(false)
Output for 5.4.32
string(28) "foo_1409986372.9568_e174f325" string(28) "foo_1409986372.9568_e174f325" bool(false)
Output for 5.4.31
string(28) "foo_1409986369.4935_621430b0" string(28) "foo_1409986369.4935_621430b0" bool(false)
Output for 5.4.30
string(28) "foo_1409986365.7777_6d1c7a19" string(28) "foo_1409986365.7777_6d1c7a19" bool(false)
Output for 5.4.29
string(27) "foo_1409986365.528_6ca81458" string(27) "foo_1409986365.528_6ca81458" bool(false)
Output for 5.4.28
string(28) "foo_1409986365.2596_5f5d269a" string(28) "foo_1409986365.2596_5f5d269a" bool(false)
Output for 5.4.27
string(28) "foo_1409986370.7555_08d63134" string(28) "foo_1409986370.7555_08d63134" bool(false)
Output for 5.4.26
string(28) "foo_1409986370.4369_aea90b1e" string(28) "foo_1409986370.4369_aea90b1e" bool(false)
Output for 5.4.25
string(28) "foo_1392275526.5626_a249aaf0" string(28) "foo_1392275526.5626_a249aaf0" bool(false)
Output for 5.4.24
string(28) "foo_1392275526.6099_96825e78" string(28) "foo_1392275526.6099_96825e78" bool(false)
Output for 5.4.23
string(28) "foo_1392275526.6724_f44f24c9" string(28) "foo_1392275526.6724_f44f24c9" bool(false)
Output for 5.4.22
string(28) "foo_1392275526.7203_6f1eacc5" string(28) "foo_1392275526.7203_6f1eacc5" bool(false)
Output for 5.4.21
string(28) "foo_1392275526.7661_83b17640" string(28) "foo_1392275526.7661_83b17640" bool(false)
Output for 5.4.20
string(28) "foo_1392275526.8252_e0fdd329" string(28) "foo_1392275526.8252_e0fdd329" bool(false)
Output for 5.4.19
string(27) "foo_1392275526.871_4aeef2ac" string(27) "foo_1392275526.871_4aeef2ac" bool(false)
Output for 5.4.18
string(28) "foo_1392275526.9156_fd423f84" string(28) "foo_1392275526.9156_fd423f84" bool(false)
Output for 5.4.17
string(28) "foo_1392275526.9604_2db00728" string(28) "foo_1392275526.9604_2db00728" bool(false)
Output for 5.4.16
string(27) "foo_1392275527.004_b7c0b310" string(27) "foo_1392275527.004_b7c0b310" bool(false)
Output for 5.4.15
string(28) "foo_1392275527.0477_35250c92" string(28) "foo_1392275527.0477_35250c92" bool(false)
Output for 5.4.14
string(28) "foo_1392275527.0919_94603c51" string(28) "foo_1392275527.0919_94603c51" bool(false)
Output for 5.4.13
string(28) "foo_1392275527.1349_e01c6e81" string(28) "foo_1392275527.1349_e01c6e81" bool(false)
Output for 5.4.12
string(28) "foo_1392275527.1794_0b9bd389" string(28) "foo_1392275527.1794_0b9bd389" bool(false)
Output for 5.4.11
string(28) "foo_1392275527.2234_416c150d" string(28) "foo_1392275527.2234_416c150d" bool(false)
Output for 5.4.10
string(28) "foo_1392275527.2673_8faf128e" string(28) "foo_1392275527.2673_8faf128e" bool(false)
Output for 5.4.9
string(28) "foo_1392275527.3139_b2126246" string(28) "foo_1392275527.3139_b2126246" bool(false)
Output for 5.4.8
string(28) "foo_1392275527.3654_e9f5574f" string(28) "foo_1392275527.3654_e9f5574f" bool(false)
Output for 5.4.7
string(28) "foo_1392275527.4114_1d2e9dce" string(28) "foo_1392275527.4114_1d2e9dce" bool(false)
Output for 5.4.6
string(28) "foo_1392275527.4674_21720359" string(28) "foo_1392275527.4674_21720359" bool(false)
Output for 5.4.5
string(28) "foo_1392275527.5142_56f27494" string(28) "foo_1392275527.5142_56f27494" bool(false)
Output for 5.4.4
string(26) "foo_1392275527.57_c4337bf4" string(26) "foo_1392275527.57_c4337bf4" bool(false)
Output for 5.4.3
string(28) "foo_1392275527.6168_8dd4ff64" string(28) "foo_1392275527.6168_8dd4ff64" bool(false)
Output for 5.4.2
string(28) "foo_1392275527.6609_2d4a4d52" string(28) "foo_1392275527.6609_2d4a4d52" bool(false)
Output for 5.4.1
string(28) "foo_1392275527.7085_cc6c903e" string(28) "foo_1392275527.7085_cc6c903e" bool(false)
Output for 5.4.0
string(28) "foo_1392275527.7562_983ad003" string(28) "foo_1392275527.7562_983ad003" bool(false)
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/huCIh on line 49
Process exited with code 255.
Output for 5.1.0 - 5.2.17
Parse error: syntax error, unexpected ':' in /in/huCIh on line 11
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected ':' in /in/huCIh 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/huCIh 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/huCIh on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/huCIh on line 3
Process exited with code 255.