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'); var_dump((string) $one, $one->equals(CommandId::fromString((string) $one)));
Output for 7.1.0
string(28) "foo_1392277736.0055_4b2e837b" bool(false)
Output for 7.0.14
string(28) "foo_1392277736.0037_8157bc97" bool(false)
Output for 7.0.6
string(28) "foo_1462260467.6051_c6ab6d3f" bool(false)
Output for 7.0.5
string(28) "foo_1459628434.3164_349d9189" bool(false)
Output for 7.0.4
string(28) "foo_1457596222.8956_cfae05b1" bool(false)
Output for 7.0.3
string(28) "foo_1458289641.8513_40ba96c2" bool(false)
Output for 7.0.2
string(28) "foo_1458656466.6369_cc724358" bool(false)
Output for 7.0.1
string(28) "foo_1458760089.6744_6eda81b3" bool(false)
Output for 7.0.0
string(26) "foo_1459024872.87_443435c1" bool(false)
Output for hhvm-3.12.0
string(28) "foo_1459196505.8118_6060269a" bool(false)
Output for hhvm-3.10.0

Process exited with code 153.
Output for 5.6.28
string(28) "foo_1392277736.0046_0fe0ed4e" bool(false)
Output for 5.6.21
string(28) "foo_1462157355.8417_419b95d7" bool(false)
Output for 5.6.20
string(28) "foo_1460229420.5125_a0ba1488" bool(false)
Output for 5.6.19
string(28) "foo_1457366352.6645_7b805bf8" bool(false)
Output for 5.6.18
string(28) "foo_1457999535.3018_b95ae904" bool(false)
Output for 5.6.17
string(28) "foo_1458391402.5511_ed1f0392" bool(false)
Output for 5.6.16
string(28) "foo_1459113996.7362_4d71109b" bool(false)
Output for 5.6.15
string(28) "foo_1459203926.1609_b529e1f4" bool(false)
Output for 5.6.14
string(28) "foo_1459558368.2191_f70a7d8d" bool(false)
Output for 5.6.13
string(28) "foo_1460695628.3616_d7fb1287" bool(false)
Output for 5.6.12
string(28) "foo_1461090644.8077_865b6e99" bool(false)
Output for 5.6.11
string(28) "foo_1461375304.1966_aeaa6ba0" bool(false)
Output for 5.6.10
string(28) "foo_1461554305.9876_a039c4d1" bool(false)
Output for 5.6.9
string(28) "foo_1461744985.1449_6780382a" bool(false)
Output for 5.6.8
string(28) "foo_1461946863.1594_2d8ffd4d" bool(false)
Output for 5.5.35
string(28) "foo_1463898785.7707_cc06745d" bool(false)
Output for 5.5.34
string(28) "foo_1460324257.5453_1320ef93" bool(false)
Output for 5.5.33
string(28) "foo_1457463315.7367_6cb2c712" bool(false)
Output for 5.5.32
string(28) "foo_1458178561.4532_ce6af102" bool(false)
Output for 5.5.31
string(28) "foo_1458487755.2111_f220fdab" bool(false)
Output for 5.5.30
string(27) "foo_1459470444.367_47094960" bool(false)
Output for 5.5.29
string(28) "foo_1460832735.8463_dce11249" bool(false)
Output for 5.5.28
string(28) "foo_1461188165.7098_d77418eb" bool(false)
Output for 5.5.27
string(28) "foo_1461283540.9012_fada0015" bool(false)
Output for 5.5.26
string(28) "foo_1461649537.8987_8ffa0f70" bool(false)
Output for 5.5.25
string(28) "foo_1461845006.7124_25c05f23" bool(false)
Output for 5.5.24
string(28) "foo_1464030349.8834_0e278c60" bool(false)
Output for 5.4.45
string(27) "foo_1442526225.245_6193bfd7" bool(false)
Output for 5.4.44
string(28) "foo_1440770924.4963_1649089d" bool(false)
Output for 5.4.43
string(28) "foo_1440770921.3876_122892be" bool(false)
Output for 5.4.42
string(28) "foo_1440770920.1214_90b3348b" bool(false)
Output for 5.4.41
string(27) "foo_1440770917.992_42df415a" bool(false)
Output for 5.4.40
string(28) "foo_1440770915.1273_942d71a9" bool(false)
Output for 5.4.39
string(28) "foo_1440770914.7217_8335654a" bool(false)
Output for 5.4.38
string(28) "foo_1425280142.6224_714440f8" bool(false)
Output for 5.4.37
string(28) "foo_1423359930.5611_33c7fa1f" bool(false)
Output for 5.4.36
string(28) "foo_1423359930.2081_00f4a912" bool(false)
Output for 5.4.35
string(28) "foo_1417713153.0755_edb59b4a" bool(false)
Output for 5.4.34
string(28) "foo_1417713152.7715_e4783bab" bool(false)
Output for 5.4.32
string(28) "foo_1409986445.3427_0d9a6b6e" bool(false)
Output for 5.4.31
string(28) "foo_1409986439.5083_7cf3cbac" bool(false)
Output for 5.4.30
string(28) "foo_1409986434.0123_9c547dcf" bool(false)
Output for 5.4.29
string(28) "foo_1409986433.5148_415c61c6" bool(false)
Output for 5.4.28
string(28) "foo_1409986433.0038_28d4827b" bool(false)
Output for 5.4.27
string(28) "foo_1409986441.9101_f1c8a540" bool(false)
Output for 5.4.26
string(28) "foo_1409986441.3159_d5bcbddd" bool(false)
Output for 5.4.25
string(28) "foo_1392277737.3545_837fa6d2" bool(false)
Output for 5.4.24
string(28) "foo_1392277737.3993_33ec7d63" bool(false)
Output for 5.4.23
string(28) "foo_1392277737.4447_97f28c16" bool(false)
Output for 5.4.22
string(28) "foo_1392277737.5004_1863b8c3" bool(false)
Output for 5.4.21
string(28) "foo_1392277737.5434_90811820" bool(false)
Output for 5.4.20
string(28) "foo_1392277737.5941_b3ccfbc7" bool(false)
Output for 5.4.19
string(28) "foo_1392277737.6395_e7bd9594" bool(false)
Output for 5.4.18
string(28) "foo_1392277737.6885_284e6e26" bool(false)
Output for 5.4.17
string(28) "foo_1392277737.7369_618e675a" bool(false)
Output for 5.4.16
string(28) "foo_1392277737.7813_f33aee04" bool(false)
Output for 5.4.15
string(28) "foo_1392277737.8321_cfbae63d" bool(false)
Output for 5.4.14
string(28) "foo_1392277737.8776_0dae26bb" bool(false)
Output for 5.4.13
string(28) "foo_1392277737.9301_66dc45c7" bool(false)
Output for 5.4.12
string(28) "foo_1392277737.9921_1555801b" bool(false)
Output for 5.4.11
string(28) "foo_1392277738.0438_f5f52ae9" bool(false)
Output for 5.4.10
string(28) "foo_1392277738.0885_5955a4c9" bool(false)
Output for 5.4.9
string(27) "foo_1392277738.133_dc004cde" bool(false)
Output for 5.4.8
string(28) "foo_1392277738.1778_781dc288" bool(true)
Output for 5.4.7
string(26) "foo_1392277738.22_458f3ff9" bool(false)
Output for 5.4.6
string(28) "foo_1392277738.2628_a5d58487" bool(false)
Output for 5.4.5
string(28) "foo_1392277738.3058_64887d5e" bool(false)
Output for 5.4.4
string(28) "foo_1392277738.3539_980e027a" bool(false)
Output for 5.4.3
string(28) "foo_1392277738.4056_f387243c" bool(false)
Output for 5.4.2
string(28) "foo_1392277738.4556_92376337" bool(false)
Output for 5.4.1
string(28) "foo_1392277738.4983_7bb930c2" bool(false)
Output for 5.4.0
string(28) "foo_1392277738.5439_e77a56c4" bool(false)
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/i2SKp on line 49
Process exited with code 255.
Output for 5.1.0 - 5.2.17
Parse error: syntax error, unexpected ':' in /in/i2SKp on line 11
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected ':' in /in/i2SKp 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/i2SKp 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/i2SKp on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/i2SKp on line 3
Process exited with code 255.