3v4l.org

run code in 300+ PHP versions simultaneously
<?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.7
string(28) "foo_1392275525.0026_db8189a1" string(28) "foo_1392275525.0026_db8189a1" bool(false)
Output for 7.1.6
string(28) "foo_1392275525.0131_a836b949" string(28) "foo_1392275525.0131_a836b949" bool(false)
Output for 7.1.5
string(28) "foo_1392275525.0112_b1e7301e" string(28) "foo_1392275525.0112_b1e7301e" bool(false)
Output for 7.1.0
string(28) "foo_1392275525.0037_29c7e2d9" string(28) "foo_1392275525.0037_29c7e2d9" bool(false)
Output for 7.0.20
string(28) "foo_1392275525.0025_593cd664" string(28) "foo_1392275525.0025_593cd664" 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 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_1392275525.0043_01f0aae8" string(28) "foo_1392275525.0043_01f0aae8" bool(false)
Output for 5.4.24
string(28) "foo_1392275525.0042_128b1663" string(28) "foo_1392275525.0042_128b1663" bool(false)
Output for 5.4.23
string(28) "foo_1392275525.0041_de0c392d" string(28) "foo_1392275525.0041_de0c392d" bool(false)
Output for 5.4.22
string(28) "foo_1392275525.0059_68e6f312" string(28) "foo_1392275525.0059_68e6f312" bool(false)
Output for 5.4.21
string(28) "foo_1392275525.0076_e3b1fd92" string(28) "foo_1392275525.0076_e3b1fd92" bool(false)
Output for 5.4.20
string(28) "foo_1392275525.0131_aa59b921" string(28) "foo_1392275525.0131_aa59b921" bool(false)
Output for 5.4.19
string(28) "foo_1392275525.0108_5b1169c3" string(28) "foo_1392275525.0108_5b1169c3" bool(false)
Output for 5.4.18
string(28) "foo_1392275525.0044_94048852" string(28) "foo_1392275525.0044_94048852" bool(false)
Output for 5.4.17
string(28) "foo_1392275525.0041_167f8d67" string(28) "foo_1392275525.0041_167f8d67" bool(false)
Output for 5.4.16
string(27) "foo_1392275525.006_bf9b3092" string(27) "foo_1392275525.006_bf9b3092" bool(false)
Output for 5.4.15
string(28) "foo_1392275525.0062_610e5e6d" string(28) "foo_1392275525.0062_610e5e6d" bool(false)
Output for 5.4.14
string(28) "foo_1392275525.0023_d59f3a29" string(28) "foo_1392275525.0023_d59f3a29" bool(false)
Output for 5.4.13
string(28) "foo_1392275525.0029_9ae42c48" string(28) "foo_1392275525.0029_9ae42c48" bool(false)
Output for 5.4.12
string(28) "foo_1392275525.0023_f0adbf61" string(28) "foo_1392275525.0023_f0adbf61" bool(false)
Output for 5.4.11
string(28) "foo_1392275525.0036_98044793" string(28) "foo_1392275525.0036_98044793" bool(false)
Output for 5.4.10
string(28) "foo_1392275525.0036_7fd196b9" string(28) "foo_1392275525.0036_7fd196b9" bool(false)
Output for 5.4.9
string(28) "foo_1392275525.0028_7117cee3" string(28) "foo_1392275525.0028_7117cee3" bool(false)
Output for 5.4.8
string(28) "foo_1392275525.0029_14286fb1" string(28) "foo_1392275525.0029_14286fb1" bool(false)
Output for 5.4.7
string(28) "foo_1392275525.0029_ed5319b5" string(28) "foo_1392275525.0029_ed5319b5" bool(false)
Output for 5.4.6
string(28) "foo_1392275525.0043_aac9f76f" string(28) "foo_1392275525.0043_aac9f76f" bool(false)
Output for 5.4.5
string(28) "foo_1392275525.0041_829c031d" string(28) "foo_1392275525.0041_829c031d" bool(false)
Output for 5.4.4
string(28) "foo_1392275525.0025_14f875a0" string(28) "foo_1392275525.0025_14f875a0" bool(false)
Output for 5.4.3
string(28) "foo_1392275525.0028_013e46aa" string(28) "foo_1392275525.0028_013e46aa" bool(false)
Output for 5.4.2
string(28) "foo_1392275525.0023_d916bdc2" string(28) "foo_1392275525.0023_d916bdc2" bool(false)
Output for 5.4.1
string(28) "foo_1392275525.0053_dea850fb" string(28) "foo_1392275525.0053_dea850fb" bool(false)
Output for 5.4.0
string(28) "foo_1392275525.0043_6769706f" string(28) "foo_1392275525.0043_6769706f" 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.1.6, 5.2.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.3.11, 4.4.0 - 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.

preferences:
160.14 ms | 401 KiB | 174 Q