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) { $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.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.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 hhvm-3.12.0
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1457687976.5414_b3061fa6" string(28) "foo_1457687976.5414_b3061fa6"
Output for hhvm-3.10.0
string(28) "foo_1459289159.7303_8497ab72" string(28) "foo_1459289159.7303_8497ab72"
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_1392274712.7691_9c7e3b71" string(28) "foo_1392274712.7691_9c7e3b71"
Output for 5.4.24
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274712.8161_ad69efa9" string(28) "foo_1392274712.8161_ad69efa9"
Output for 5.4.23
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274712.8715_879ac8ff" string(28) "foo_1392274712.8715_879ac8ff"
Output for 5.4.22
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(27) "foo_1392274712.919_a1296869" string(27) "foo_1392274712.919_a1296869"
Output for 5.4.21
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274712.9655_d649434b" string(28) "foo_1392274712.9655_d649434b"
Output for 5.4.20
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274713.0121_163839a9" string(28) "foo_1392274713.0121_163839a9"
Output for 5.4.19
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274713.0571_ccb0d4c3" string(28) "foo_1392274713.0571_ccb0d4c3"
Output for 5.4.18
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274713.1013_9903a258" string(28) "foo_1392274713.1013_9903a258"
Output for 5.4.17
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274713.1464_977cecc2" string(28) "foo_1392274713.1464_977cecc2"
Output for 5.4.16
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274713.1912_c75f1279" string(28) "foo_1392274713.1912_c75f1279"
Output for 5.4.15
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274713.2385_079a40d0" string(28) "foo_1392274713.2385_079a40d0"
Output for 5.4.14
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274713.2848_bc81007e" string(28) "foo_1392274713.2848_bc81007e"
Output for 5.4.13
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274713.3286_f6406b01" string(28) "foo_1392274713.3286_f6406b01"
Output for 5.4.12
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274713.3737_fcddf0a2" string(28) "foo_1392274713.3737_fcddf0a2"
Output for 5.4.11
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274713.4181_b3742f59" string(28) "foo_1392274713.4181_b3742f59"
Output for 5.4.10
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274713.4667_30baa471" string(28) "foo_1392274713.4667_30baa471"
Output for 5.4.9
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(27) "foo_1392274713.518_49df0df5" string(27) "foo_1392274713.518_49df0df5"
Output for 5.4.8
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274713.5781_9f8202ec" string(28) "foo_1392274713.5781_9f8202ec"
Output for 5.4.7
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274713.6239_36a3edc1" string(28) "foo_1392274713.6239_36a3edc1"
Output for 5.4.6
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274713.6671_2d8c69a9" string(28) "foo_1392274713.6671_2d8c69a9"
Output for 5.4.5
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274713.7113_7500316a" string(28) "foo_1392274713.7113_7500316a"
Output for 5.4.4
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274713.7564_baa13c1c" string(28) "foo_1392274713.7564_baa13c1c"
Output for 5.4.3
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274713.8032_8600a994" string(28) "foo_1392274713.8032_8600a994"
Output for 5.4.2
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274713.8515_8a974978" string(28) "foo_1392274713.8515_8a974978"
Output for 5.4.1
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274713.9013_c1fd841e" string(28) "foo_1392274713.9013_c1fd841e"
Output for 5.4.0
Warning: assert(): Assertion failed in /in/23r4P on line 60 string(28) "foo_1392274713.9488_d0a3586a" string(28) "foo_1392274713.9488_d0a3586a"
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.