3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php final class CommandId { private $name; private $time; private $hash; public function __construct($name) { $this->time = microtime(true); $this->name = trim($name); $this->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]"); } $id = new static($parts[0]); $id->time = (float) $parts[1]; $id->hash = $parts[2]; return $id; } 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.2.0
Warning: assert(): assert($one->equals($two)) failed in /in/23r4P on line 60 string(27) "foo_1392274711.005_97b1186e" string(27) "foo_1392274711.005_97b1186e"
Output for 7.1.7
Warning: assert(): assert($one->equals($two)) failed in /in/23r4P on line 60 string(28) "foo_1392274711.0037_8161972c" string(28) "foo_1392274711.0037_8161972c"
Output for 7.1.6
Warning: assert(): assert($one->equals($two)) failed in /in/23r4P on line 60 string(27) "foo_1392274711.006_0ea59f4c" string(27) "foo_1392274711.006_0ea59f4c"
Output for 7.1.5
Warning: assert(): assert($one->equals($two)) failed in /in/23r4P on line 60 string(27) "foo_1392274711.011_adad13cd" string(27) "foo_1392274711.011_adad13cd"
Output for 7.1.0
Warning: assert(): assert($one->equals($two)) failed in /in/23r4P on line 60 string(27) "foo_1392274711.006_61923b15" string(27) "foo_1392274711.006_61923b15"
Output for 7.0.20
Warning: assert(): assert($one->equals($two)) failed in /in/23r4P on line 60 string(28) "foo_1392274711.0056_20b10002" string(28) "foo_1392274711.0056_20b10002"
Output for 7.0.14
Warning: assert(): assert($one->equals($two)) failed in /in/23r4P on line 60 string(28) "foo_1392274711.0039_4d2d10bd" string(28) "foo_1392274711.0039_4d2d10bd"
Output for 7.0.6
Warning: assert(): assert($one->equals($two)) failed in /in/23r4P on line 60 string(28) "foo_1462243290.2641_835d514c" string(28) "foo_1462243290.2641_835d514c"
Output for 7.0.5
Warning: assert(): assert($one->equals($two)) failed in /in/23r4P on line 60 string(28) "foo_1459612257.1548_75241126" string(28) "foo_1459612257.1548_75241126"
Output for 7.0.4
Warning: assert(): assert($one->equals($two)) failed in /in/23r4P on line 60 string(28) "foo_1457577547.4649_a823b866" string(28) "foo_1457577547.4649_a823b866"
Output for 7.0.3
Warning: assert(): assert($one->equals($two)) failed in /in/23r4P on line 60 string(28) "foo_1458269800.1039_003a6d89" string(28) "foo_1458269800.1039_003a6d89"
Output for 7.0.2
Warning: assert(): assert($one->equals($two)) failed in /in/23r4P on line 60 string(28) "foo_1458566766.7518_3dc6994d" string(28) "foo_1458566766.7518_3dc6994d"
Output for 7.0.1
Warning: assert(): assert($one->equals($two)) failed in /in/23r4P on line 60 string(28) "foo_1458740448.3156_2a577538" string(28) "foo_1458740448.3156_2a577538"
Output for 7.0.0
Warning: assert(): assert($one->equals($two)) failed in /in/23r4P on line 60 string(28) "foo_1459007759.3907_51f871d0" string(28) "foo_1459007759.3907_51f871d0"
Output for 5.6.28
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274711.0045_2ec3a31f" string(28) "foo_1392274711.0045_2ec3a31f"
Output for 5.6.21
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(27) "foo_1462139103.974_03d737f4" string(27) "foo_1462139103.974_03d737f4"
Output for 5.6.20
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1460199963.0847_47fc00af" string(28) "foo_1460199963.0847_47fc00af"
Output for 5.6.19
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1457315204.4272_fe63af30" string(28) "foo_1457315204.4272_fe63af30"
Output for 5.6.18
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1457968174.7496_66c20fb2" string(28) "foo_1457968174.7496_66c20fb2"
Output for 5.6.17
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1458372164.9641_63148611" string(28) "foo_1458372164.9641_63148611"
Output for 5.6.16
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1459096944.8637_3650d86d" string(28) "foo_1459096944.8637_3650d86d"
Output for 5.6.15
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1459186487.6903_6075956b" string(28) "foo_1459186487.6903_6075956b"
Output for 5.6.14
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1459541292.7976_9c9a17ef" string(28) "foo_1459541292.7976_9c9a17ef"
Output for 5.6.13
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1460678842.4982_386b6259" string(28) "foo_1460678842.4982_386b6259"
Output for 5.6.12
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(27) "foo_1461071797.845_fca8659b" string(27) "foo_1461071797.845_fca8659b"
Output for 5.6.11
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1461357102.2681_ba185fc7" string(28) "foo_1461357102.2681_ba185fc7"
Output for 5.6.10
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1461535786.9021_2134d859" string(28) "foo_1461535786.9021_2134d859"
Output for 5.6.9
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1461727317.3043_27f374c0" string(28) "foo_1461727317.3043_27f374c0"
Output for 5.6.8
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1461928183.0334_1594f2d8" string(28) "foo_1461928183.0334_1594f2d8"
Output for 5.6.7
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1464132457.5849_28902b66" string(28) "foo_1464132457.5849_28902b66"
Output for 5.5.35
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1463880107.7556_2d7a0986" string(28) "foo_1463880107.7556_2d7a0986"
Output for 5.5.34
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1460307802.0628_eb8d527f" string(28) "foo_1460307802.0628_eb8d527f"
Output for 5.5.33
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1457444009.1486_bbf32608" string(28) "foo_1457444009.1486_bbf32608"
Output for 5.5.32
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(27) "foo_1458156117.619_807bbfae" string(27) "foo_1458156117.619_807bbfae"
Output for 5.5.31
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1458468877.3282_f35fb9fb" string(28) "foo_1458468877.3282_f35fb9fb"
Output for 5.5.30
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1459452951.5299_9fcb568d" string(28) "foo_1459452951.5299_9fcb568d"
Output for 5.5.29
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1460815914.6851_e4c71d83" string(28) "foo_1460815914.6851_e4c71d83"
Output for 5.5.28
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1461170041.8911_302e2adf" string(28) "foo_1461170041.8911_302e2adf"
Output for 5.5.27
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1461265071.1391_b73535be" string(28) "foo_1461265071.1391_b73535be"
Output for 5.5.26
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1461631310.4455_e0240172" string(28) "foo_1461631310.4455_e0240172"
Output for 5.5.25
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(27) "foo_1461825634.947_e5af6e58" string(27) "foo_1461825634.947_e5af6e58"
Output for 5.5.24
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1464010169.5203_80ed41a7" string(28) "foo_1464010169.5203_80ed41a7"
Output for 5.4.45
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1441728457.6806_998a885c" string(28) "foo_1441728457.6806_998a885c"
Output for 5.4.44
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1439680385.8589_75d876b5" string(28) "foo_1439680385.8589_75d876b5"
Output for 5.4.43
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(27) "foo_1439680381.919_10d4c6fc" string(27) "foo_1439680381.919_10d4c6fc"
Output for 5.4.42
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1439680380.7066_a4004d39" string(28) "foo_1439680380.7066_a4004d39"
Output for 5.4.41
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(27) "foo_1439680378.662_f1e82364" string(27) "foo_1439680378.662_f1e82364"
Output for 5.4.40
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1431065234.7102_86504dfc" string(28) "foo_1431065234.7102_86504dfc"
Output for 5.4.39
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1431065233.8079_833a1f48" string(28) "foo_1431065233.8079_833a1f48"
Output for 5.4.38
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1425280093.6863_cc965d65" string(28) "foo_1425280093.6863_cc965d65"
Output for 5.4.37
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1423359827.2359_aae1b68f" string(28) "foo_1423359827.2359_aae1b68f"
Output for 5.4.36
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1423359826.8953_9056efe8" string(28) "foo_1423359826.8953_9056efe8"
Output for 5.4.35
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1417713243.4574_1d54b8cd" string(28) "foo_1417713243.4574_1d54b8cd"
Output for 5.4.34
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(27) "foo_1417713243.153_97eb841b" string(27) "foo_1417713243.153_97eb841b"
Output for 5.4.32
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(27) "foo_1409986277.552_440f2947" string(27) "foo_1409986277.552_440f2947"
Output for 5.4.31
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1409986273.1755_52ce3515" string(28) "foo_1409986273.1755_52ce3515"
Output for 5.4.30
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1409986268.9136_162819b6" string(28) "foo_1409986268.9136_162819b6"
Output for 5.4.29
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1409986268.5321_6e768448" string(28) "foo_1409986268.5321_6e768448"
Output for 5.4.28
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1409986268.1108_f24531c3" string(28) "foo_1409986268.1108_f24531c3"
Output for 5.4.27
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1409986274.9419_27b1366f" string(28) "foo_1409986274.9419_27b1366f"
Output for 5.4.26
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1409986274.5059_4c01a519" string(28) "foo_1409986274.5059_4c01a519"
Output for 5.4.25
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274711.0055_811de102" string(28) "foo_1392274711.0055_811de102"
Output for 5.4.24
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(27) "foo_1392274711.008_3c37ad8f" string(27) "foo_1392274711.008_3c37ad8f"
Output for 5.4.23
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274711.0041_e91a4048" string(28) "foo_1392274711.0041_e91a4048"
Output for 5.4.22
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274711.0082_18af46ca" string(28) "foo_1392274711.0082_18af46ca"
Output for 5.4.21
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274711.0042_f72dea06" string(28) "foo_1392274711.0042_f72dea06"
Output for 5.4.20
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274711.0042_ec5bada0" string(28) "foo_1392274711.0042_ec5bada0"
Output for 5.4.19
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274711.0049_e6657f40" string(28) "foo_1392274711.0049_e6657f40"
Output for 5.4.18
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(27) "foo_1392274711.004_88206a5f" string(27) "foo_1392274711.004_88206a5f"
Output for 5.4.17
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274711.0057_5f0f4beb" string(28) "foo_1392274711.0057_5f0f4beb"
Output for 5.4.16
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274711.0039_e2385cd7" string(28) "foo_1392274711.0039_e2385cd7"
Output for 5.4.15
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274711.0041_89483653" string(28) "foo_1392274711.0041_89483653"
Output for 5.4.14
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274711.0023_8d98b6ca" string(28) "foo_1392274711.0023_8d98b6ca"
Output for 5.4.13
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274711.0027_682d7dcc" string(28) "foo_1392274711.0027_682d7dcc"
Output for 5.4.12
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274711.0022_588e1f0c" string(28) "foo_1392274711.0022_588e1f0c"
Output for 5.4.11
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274711.0028_d734b3c7" string(28) "foo_1392274711.0028_d734b3c7"
Output for 5.4.10
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274711.0023_e3fa0b1e" string(28) "foo_1392274711.0023_e3fa0b1e"
Output for 5.4.9
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274711.0022_6224fcf1" string(28) "foo_1392274711.0022_6224fcf1"
Output for 5.4.8
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274711.0023_09fa049c" string(28) "foo_1392274711.0023_09fa049c"
Output for 5.4.7
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274711.0028_20654753" string(28) "foo_1392274711.0028_20654753"
Output for 5.4.6
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274711.0026_0099334a" string(28) "foo_1392274711.0026_0099334a"
Output for 5.4.5
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274711.0036_c15d83cb" string(28) "foo_1392274711.0036_c15d83cb"
Output for 5.4.4
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274711.0026_99c1b6df" string(28) "foo_1392274711.0026_99c1b6df"
Output for 5.4.3
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274711.0035_603fcdd6" string(28) "foo_1392274711.0035_603fcdd6"
Output for 5.4.2
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274711.0024_c88d716b" string(28) "foo_1392274711.0024_c88d716b"
Output for 5.4.1
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274711.0032_c0f2f9da" string(28) "foo_1392274711.0032_c0f2f9da"
Output for 5.4.0
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274711.0024_16035707" string(28) "foo_1392274711.0024_16035707"
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/23r4P on line 54
Process exited with code 255.
Output for 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_STATIC, expecting T_STRING or T_VARIABLE or '$' in /in/23r4P on line 26
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_STATIC, expecting T_STRING or T_VARIABLE or '$' in /in/23r4P on line 26
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_CLASS in /in/23r4P 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/23r4P on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/23r4P on line 3
Process exited with code 255.