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->equals($two));
Output for 7.1.0
string(28) "foo_1392277576.0067_8ddcfad7" string(28) "foo_1392277576.0067_8ddcfad7" bool(false)
Output for 7.0.14
string(28) "foo_1392277576.0037_be6e35a6" string(28) "foo_1392277576.0037_be6e35a6" bool(false)
Output for 7.0.10
string(27) "foo_1392277576.003_f13835f9" string(27) "foo_1392277576.003_f13835f9" bool(false)
Output for 7.0.9
string(28) "foo_1392277576.0042_31e04905" string(28) "foo_1392277576.0042_31e04905" bool(false)
Output for 7.0.8
string(28) "foo_1392277576.0035_2088cf77" string(28) "foo_1392277576.0035_2088cf77" bool(false)
Output for 7.0.7
string(28) "foo_1392277576.0029_687e28bb" string(28) "foo_1392277576.0029_687e28bb" bool(false)
Output for 7.0.6
string(27) "foo_1392277576.003_bfef53e4" string(27) "foo_1392277576.003_bfef53e4" bool(false)
Output for 7.0.5
string(28) "foo_1392277576.0034_a2f234a5" string(28) "foo_1392277576.0034_a2f234a5" bool(false)
Output for 7.0.4
string(28) "foo_1392277576.0043_8d9fce25" string(28) "foo_1392277576.0043_8d9fce25" bool(false)
Output for 7.0.3
string(28) "foo_1392277576.0037_f1d46aac" string(28) "foo_1392277576.0037_f1d46aac" bool(false)
Output for 7.0.2
string(28) "foo_1392277576.0045_d6737cf0" string(28) "foo_1392277576.0045_d6737cf0" bool(false)
Output for 7.0.1
string(28) "foo_1392277576.0039_183e41c3" string(28) "foo_1392277576.0039_183e41c3" bool(false)
Output for 7.0.0
string(28) "foo_1392277576.0034_b8baa1bf" string(28) "foo_1392277576.0034_b8baa1bf" bool(false)
Output for hhvm-3.12.0
string(28) "foo_1392277576.1749_541307e4" string(28) "foo_1392277576.1749_541307e4" bool(false)
Output for hhvm-3.10.0
string(28) "foo_1392277576.2633_4bf04660" string(28) "foo_1392277576.2633_4bf04660" bool(false)
Output for 5.6.28
string(28) "foo_1392277576.0046_01e7f421" string(28) "foo_1392277576.0046_01e7f421" bool(false)
Output for 5.6.25
string(28) "foo_1392277576.0032_47481697" string(28) "foo_1392277576.0032_47481697" bool(false)
Output for 5.6.24
string(27) "foo_1392277576.004_9916fde6" string(27) "foo_1392277576.004_9916fde6" bool(false)
Output for 5.6.23
string(28) "foo_1392277576.0044_e9de2c3c" string(28) "foo_1392277576.0044_e9de2c3c" bool(false)
Output for 5.6.22
string(28) "foo_1392277576.0048_3e540574" string(28) "foo_1392277576.0048_3e540574" bool(false)
Output for 5.6.21
string(28) "foo_1392277576.0036_eda92527" string(28) "foo_1392277576.0036_eda92527" bool(false)
Output for 5.6.20
string(28) "foo_1392277576.0048_3e3c220d" string(28) "foo_1392277576.0048_3e3c220d" bool(false)
Output for 5.6.19
string(28) "foo_1392277576.0029_a8eaa8ff" string(28) "foo_1392277576.0029_a8eaa8ff" bool(false)
Output for 5.6.18
string(27) "foo_1392277576.004_959cfab7" string(27) "foo_1392277576.004_959cfab7" bool(false)
Output for 5.6.17
string(28) "foo_1392277576.0031_17ff8132" string(28) "foo_1392277576.0031_17ff8132" bool(false)
Output for 5.6.16
string(28) "foo_1392277576.0041_d27746af" string(28) "foo_1392277576.0041_d27746af" bool(false)
Output for 5.6.15
string(28) "foo_1392277576.0042_0f862e51" string(28) "foo_1392277576.0042_0f862e51" bool(false)
Output for 5.6.14
string(28) "foo_1392277576.0033_a5846b31" string(28) "foo_1392277576.0033_a5846b31" bool(false)
Output for 5.6.13
string(28) "foo_1392277576.0042_b52d9fc5" string(28) "foo_1392277576.0042_b52d9fc5" bool(false)
Output for 5.6.12
string(28) "foo_1392277576.0032_02f91b4a" string(28) "foo_1392277576.0032_02f91b4a" bool(false)
Output for 5.6.11
string(28) "foo_1392277576.0036_f1e2f06f" string(28) "foo_1392277576.0036_f1e2f06f" bool(false)
Output for 5.6.10
string(28) "foo_1392277576.0037_67af3423" string(28) "foo_1392277576.0037_67af3423" bool(false)
Output for 5.6.9
string(28) "foo_1392277576.0033_e0e319ac" string(28) "foo_1392277576.0033_e0e319ac" bool(false)
Output for 5.6.8
string(28) "foo_1392277576.0035_81081aeb" string(28) "foo_1392277576.0035_81081aeb" bool(false)
Output for 5.6.7
string(28) "foo_1392277576.0028_131895c7" string(28) "foo_1392277576.0028_131895c7" bool(false)
Output for 5.6.6
string(28) "foo_1392277576.0028_074988cc" string(28) "foo_1392277576.0028_074988cc" bool(false)
Output for 5.6.5
string(28) "foo_1392277576.0039_c6c51638" string(28) "foo_1392277576.0039_c6c51638" bool(false)
Output for 5.6.4
string(28) "foo_1392277576.0029_cf45f92f" string(28) "foo_1392277576.0029_cf45f92f" bool(false)
Output for 5.6.3
string(28) "foo_1392277576.0028_5d9ebd52" string(28) "foo_1392277576.0028_5d9ebd52" bool(false)
Output for 5.6.2
string(28) "foo_1392277576.0029_6ae9cdd0" string(28) "foo_1392277576.0029_6ae9cdd0" bool(false)
Output for 5.6.1
string(28) "foo_1392277576.0026_8f104270" string(28) "foo_1392277576.0026_8f104270" bool(false)
Output for 5.6.0
string(28) "foo_1392277576.0023_baa3fca2" string(28) "foo_1392277576.0023_baa3fca2" bool(false)
Output for 5.5.38
string(28) "foo_1392277576.0042_6678157b" string(28) "foo_1392277576.0042_6678157b" bool(false)
Output for 5.5.37
string(28) "foo_1392277576.0035_14fc0a1c" string(28) "foo_1392277576.0035_14fc0a1c" bool(false)
Output for 5.5.36
string(28) "foo_1392277576.0046_91438d34" string(28) "foo_1392277576.0046_91438d34" bool(false)
Output for 5.5.35
string(28) "foo_1392277576.0035_c82dc0f7" string(28) "foo_1392277576.0035_c82dc0f7" bool(false)
Output for 5.5.34
string(28) "foo_1392277576.0048_a9dc3d19" string(28) "foo_1392277576.0048_a9dc3d19" bool(false)
Output for 5.5.33
string(27) "foo_1392277576.003_e66982e1" string(27) "foo_1392277576.003_e66982e1" bool(false)
Output for 5.5.32
string(27) "foo_1392277576.005_4a739832" string(27) "foo_1392277576.005_4a739832" bool(false)
Output for 5.5.31
string(28) "foo_1392277576.0044_498c0e75" string(28) "foo_1392277576.0044_498c0e75" bool(false)
Output for 5.5.30
string(28) "foo_1392277576.0031_1f841e2a" string(28) "foo_1392277576.0031_1f841e2a" bool(false)
Output for 5.5.29
string(28) "foo_1392277576.0033_cfd1e5f1" string(28) "foo_1392277576.0033_cfd1e5f1" bool(false)
Output for 5.5.28
string(28) "foo_1392277576.0032_f4ba2adb" string(28) "foo_1392277576.0032_f4ba2adb" bool(false)
Output for 5.5.27
string(28) "foo_1392277576.0028_1ae6cc83" string(28) "foo_1392277576.0028_1ae6cc83" bool(false)
Output for 5.5.26
string(28) "foo_1392277576.0028_17175bd9" string(28) "foo_1392277576.0028_17175bd9" bool(false)
Output for 5.5.25
string(28) "foo_1392277576.0032_711a4e6b" string(28) "foo_1392277576.0032_711a4e6b" bool(false)
Output for 5.5.24
string(27) "foo_1392277576.003_4af83e4e" string(27) "foo_1392277576.003_4af83e4e" bool(false)
Output for 5.5.23
string(28) "foo_1392277576.0028_1fde89f8" string(28) "foo_1392277576.0028_1fde89f8" bool(false)
Output for 5.5.22
string(27) "foo_1392277576.003_cb745393" string(27) "foo_1392277576.003_cb745393" bool(false)
Output for 5.5.21
string(28) "foo_1392277576.0035_30b95a30" string(28) "foo_1392277576.0035_30b95a30" bool(false)
Output for 5.5.20
string(28) "foo_1392277576.0028_5e8c7d43" string(28) "foo_1392277576.0028_5e8c7d43" bool(false)
Output for 5.5.19
string(28) "foo_1392277576.0028_531bce39" string(28) "foo_1392277576.0028_531bce39" bool(false)
Output for 5.5.18
string(28) "foo_1392277576.0036_1a8dc69f" string(28) "foo_1392277576.0036_1a8dc69f" bool(false)
Output for 5.5.16
string(28) "foo_1392277576.0024_011c42e0" string(28) "foo_1392277576.0024_011c42e0" bool(false)
Output for 5.5.15
string(28) "foo_1392277576.0028_13f6243d" string(28) "foo_1392277576.0028_13f6243d" bool(false)
Output for 5.5.14
string(28) "foo_1392277576.0027_d6c2b8ed" string(28) "foo_1392277576.0027_d6c2b8ed" bool(false)
Output for 5.5.13
string(28) "foo_1392277576.0044_49074e14" string(28) "foo_1392277576.0044_49074e14" bool(false)
Output for 5.5.12
string(28) "foo_1392277576.0024_8d5b56d2" string(28) "foo_1392277576.0024_8d5b56d2" bool(false)
Output for 5.5.11
string(28) "foo_1392277576.0024_09326c31" string(28) "foo_1392277576.0024_09326c31" bool(false)
Output for 5.5.10
string(28) "foo_1392277576.0036_dce68cbf" string(28) "foo_1392277576.0036_dce68cbf" bool(false)
Output for 5.5.9
string(28) "foo_1392277576.0028_84d84ef7" string(28) "foo_1392277576.0028_84d84ef7" bool(false)
Output for 5.5.8
string(28) "foo_1392277576.0031_d01096a3" string(28) "foo_1392277576.0031_d01096a3" bool(false)
Output for 5.5.7
string(28) "foo_1392277576.0039_22aeea84" string(28) "foo_1392277576.0039_22aeea84" bool(false)
Output for 5.5.6
string(28) "foo_1392277576.0038_5c8bb2ae" string(28) "foo_1392277576.0038_5c8bb2ae" bool(false)
Output for 5.5.5
string(28) "foo_1392277576.0034_0ae49b2d" string(28) "foo_1392277576.0034_0ae49b2d" bool(false)
Output for 5.5.4
string(27) "foo_1392277576.004_499ab3b7" string(27) "foo_1392277576.004_499ab3b7" bool(false)
Output for 5.5.3
string(28) "foo_1392277576.0048_60fbe838" string(28) "foo_1392277576.0048_60fbe838" bool(false)
Output for 5.5.2
string(27) "foo_1392277576.004_44e53050" string(27) "foo_1392277576.004_44e53050" bool(false)
Output for 5.5.1
string(28) "foo_1392277576.0048_0efb4865" string(28) "foo_1392277576.0048_0efb4865" bool(false)
Output for 5.5.0
string(28) "foo_1392277576.0047_1a508a4c" string(28) "foo_1392277576.0047_1a508a4c" bool(false)
Output for 5.4.45
string(28) "foo_1392277576.0031_d0c4b4bc" string(28) "foo_1392277576.0031_d0c4b4bc" bool(false)
Output for 5.4.44
string(28) "foo_1392277576.0024_3684ac4e" string(28) "foo_1392277576.0024_3684ac4e" bool(false)
Output for 5.4.43
string(28) "foo_1392277576.0024_0c50a98c" string(28) "foo_1392277576.0024_0c50a98c" bool(false)
Output for 5.4.42
string(28) "foo_1392277576.0031_7c4dbed0" string(28) "foo_1392277576.0031_7c4dbed0" bool(false)
Output for 5.4.41
string(28) "foo_1392277576.0027_e867615c" string(28) "foo_1392277576.0027_e867615c" bool(false)
Output for 5.4.40
string(28) "foo_1392277576.0027_576eb2cc" string(28) "foo_1392277576.0027_576eb2cc" bool(false)
Output for 5.4.39
string(28) "foo_1392277576.0026_0b27056d" string(28) "foo_1392277576.0026_0b27056d" bool(false)
Output for 5.4.38
string(28) "foo_1392277576.0025_1a78b939" string(28) "foo_1392277576.0025_1a78b939" bool(false)
Output for 5.4.37
string(28) "foo_1392277576.0028_392f6252" string(28) "foo_1392277576.0028_392f6252" bool(false)
Output for 5.4.36
string(28) "foo_1392277576.0027_13a57961" string(28) "foo_1392277576.0027_13a57961" bool(false)
Output for 5.4.35
string(28) "foo_1392277576.0027_f0d3254e" string(28) "foo_1392277576.0027_f0d3254e" bool(false)
Output for 5.4.34
string(28) "foo_1392277576.0031_60a6ca04" string(28) "foo_1392277576.0031_60a6ca04" bool(false)
Output for 5.4.32
string(28) "foo_1392277576.0021_667d3bc9" string(28) "foo_1392277576.0021_667d3bc9" bool(false)
Output for 5.4.31
string(28) "foo_1392277576.0021_ad92a39b" string(28) "foo_1392277576.0021_ad92a39b" bool(false)
Output for 5.4.30
string(28) "foo_1392277576.0026_43be5b7a" string(28) "foo_1392277576.0026_43be5b7a" bool(false)
Output for 5.4.29
string(28) "foo_1392277576.0022_76610ff8" string(28) "foo_1392277576.0022_76610ff8" bool(false)
Output for 5.4.28
string(28) "foo_1392277576.0026_466da109" string(28) "foo_1392277576.0026_466da109" bool(false)
Output for 5.4.27
string(28) "foo_1392277576.0025_c11f4dce" string(28) "foo_1392277576.0025_c11f4dce" bool(false)
Output for 5.4.26
string(28) "foo_1392277576.0026_2f201df5" string(28) "foo_1392277576.0026_2f201df5" bool(false)
Output for 5.4.25
string(28) "foo_1392277576.0025_1d8511aa" string(28) "foo_1392277576.0025_1d8511aa" bool(false)
Output for 5.4.24
string(27) "foo_1392277576.002_54f9ca5c" string(27) "foo_1392277576.002_54f9ca5c" bool(false)
Output for 5.4.23
string(28) "foo_1392277576.0036_88d7c0bb" string(28) "foo_1392277576.0036_88d7c0bb" bool(false)
Output for 5.4.22
string(28) "foo_1392277576.0033_dfc26e96" string(28) "foo_1392277576.0033_dfc26e96" bool(false)
Output for 5.4.21
string(28) "foo_1392277576.0037_8c852669" string(28) "foo_1392277576.0037_8c852669" bool(false)
Output for 5.4.20
string(28) "foo_1392277576.0025_6f289abd" string(28) "foo_1392277576.0025_6f289abd" bool(false)
Output for 5.4.19
string(28) "foo_1392277576.0039_a2358609" string(28) "foo_1392277576.0039_a2358609" bool(false)
Output for 5.4.18
string(28) "foo_1392277576.0037_3838b89c" string(28) "foo_1392277576.0037_3838b89c" bool(false)
Output for 5.4.17
string(28) "foo_1392277576.0036_1c32fa5c" string(28) "foo_1392277576.0036_1c32fa5c" bool(false)
Output for 5.4.16
string(28) "foo_1392277576.0035_11c7e310" string(28) "foo_1392277576.0035_11c7e310" bool(false)
Output for 5.4.15
string(28) "foo_1392277576.0032_3f993b61" string(28) "foo_1392277576.0032_3f993b61" bool(false)
Output for 5.4.14
string(27) "foo_1392277576.002_1a7adb61" string(27) "foo_1392277576.002_1a7adb61" bool(false)
Output for 5.4.13
string(28) "foo_1392277576.0021_80a4ba30" string(28) "foo_1392277576.0021_80a4ba30" bool(false)
Output for 5.4.12
string(28) "foo_1392277576.0015_f76eaa19" string(28) "foo_1392277576.0015_f76eaa19" bool(false)
Output for 5.4.11
string(28) "foo_1392277576.0018_b1c821dc" string(28) "foo_1392277576.0018_b1c821dc" bool(false)
Output for 5.4.10
string(28) "foo_1392277576.0016_e3dfcf50" string(28) "foo_1392277576.0016_e3dfcf50" bool(false)
Output for 5.4.9
string(28) "foo_1392277576.0024_14858ce5" string(28) "foo_1392277576.0024_14858ce5" bool(false)
Output for 5.4.8
string(28) "foo_1392277576.0014_fe8adec9" string(28) "foo_1392277576.0014_fe8adec9" bool(false)
Output for 5.4.7
string(27) "foo_1392277576.002_1e2dc09c" string(27) "foo_1392277576.002_1e2dc09c" bool(false)
Output for 5.4.6
string(28) "foo_1392277576.0024_fe6abc9f" string(28) "foo_1392277576.0024_fe6abc9f" bool(false)
Output for 5.4.5
string(28) "foo_1392277576.0023_db077fb4" string(28) "foo_1392277576.0023_db077fb4" bool(false)
Output for 5.4.4
string(28) "foo_1392277576.0021_2bd3f9c8" string(28) "foo_1392277576.0021_2bd3f9c8" bool(false)
Output for 5.4.3
string(28) "foo_1392277576.0023_d4208bfa" string(28) "foo_1392277576.0023_d4208bfa" bool(false)
Output for 5.4.2
string(28) "foo_1392277576.0025_183b64db" string(28) "foo_1392277576.0025_183b64db" bool(false)
Output for 5.4.1
string(28) "foo_1392277576.0022_4e992a72" string(28) "foo_1392277576.0022_4e992a72" bool(false)
Output for 5.4.0
string(28) "foo_1392277576.0022_499ac295" string(28) "foo_1392277576.0022_499ac295" bool(false)
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/IRYJm on line 49
Process exited with code 255.
Output for 5.1.0 - 5.2.17
Parse error: syntax error, unexpected ':' in /in/IRYJm on line 11
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected ':' in /in/IRYJm 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/IRYJm 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/IRYJm on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/IRYJm on line 3
Process exited with code 255.