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 = 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]"); } return new static($parts[0], (float) $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); assert($one->equals($two)); var_dump((string) $one, (string) $two);
Output for 7.1.0
Warning: assert(): assert($one->equals($two)) failed in /in/BaGmh on line 56 string(28) "foo_1392274844.0066_ed497b26" string(28) "foo_1392274844.0066_6f1ff994"
Output for 7.0.14
Warning: assert(): assert($one->equals($two)) failed in /in/BaGmh on line 56 string(28) "foo_1392274844.0039_35a31320" string(27) "foo_1392274844.004_cb827ba3"
Output for 7.0.6
Warning: assert(): assert($one->equals($two)) failed in /in/BaGmh on line 56 string(28) "foo_1462233637.1674_30d760cb" string(28) "foo_1462233637.1674_537f3b2c"
Output for 7.0.5
Warning: assert(): assert($one->equals($two)) failed in /in/BaGmh on line 56 string(28) "foo_1459603065.6207_b55944d2" string(28) "foo_1459603065.6207_deac4f81"
Output for 7.0.4
Warning: assert(): assert($one->equals($two)) failed in /in/BaGmh on line 56 string(28) "foo_1457567064.9944_67641f8c" string(28) "foo_1457567064.9944_5b4cb7f9"
Output for 7.0.3
Warning: assert(): assert($one->equals($two)) failed in /in/BaGmh on line 56 string(28) "foo_1458259001.0999_523557d1" string(28) "foo_1458259001.0999_7d847396"
Output for 7.0.2
Warning: assert(): assert($one->equals($two)) failed in /in/BaGmh on line 56 string(28) "foo_1458556327.0741_cbe11719" string(28) "foo_1458556327.0741_8635b116"
Output for 7.0.1
Warning: assert(): assert($one->equals($two)) failed in /in/BaGmh on line 56 string(28) "foo_1458729816.9596_4e031290" string(28) "foo_1458729816.9596_e8d65579"
Output for 7.0.0
Warning: assert(): assert($one->equals($two)) failed in /in/BaGmh on line 56 string(28) "foo_1458998154.3429_6adefed1" string(28) "foo_1458998154.3429_cefc3ec4"
Output for 5.6.28
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1392274844.0045_f545b1f2" string(28) "foo_1392274844.0045_0de38f6a"
Output for 5.6.21
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1462129470.5584_4ec8c426" string(28) "foo_1462129470.5585_22a51c1e"
Output for 5.6.20
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1460190761.0597_cde93257" string(28) "foo_1460190761.0598_671e4421"
Output for 5.6.19
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1457301249.3466_10c28bd4" string(28) "foo_1457301249.3467_e8f93fa0"
Output for 5.6.18
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1457947363.6157_9229974a" string(28) "foo_1457947363.6157_eed4d30b"
Output for 5.6.17
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1458361553.1549_af613686" string(27) "foo_1458361553.155_d411a2bd"
Output for 5.6.16
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1459087177.9762_50e4d504" string(28) "foo_1459087177.9762_c6753d0e"
Output for 5.6.15
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1459176832.9056_2bd66a60" string(28) "foo_1459176832.9056_036b890a"
Output for 5.6.14
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1459532006.9702_d42fc370" string(28) "foo_1459532006.9703_5d1f3574"
Output for 5.6.13
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1460668878.6576_c040ed3f" string(28) "foo_1460668878.6576_89be7da6"
Output for 5.6.12
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1461061741.4127_50e09a7d" string(28) "foo_1461061741.4128_0432fa6c"
Output for 5.6.11
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1461347113.6305_118b25e3" string(28) "foo_1461347113.6305_988bee8f"
Output for 5.6.10
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1461525910.7895_c4314c27" string(28) "foo_1461525910.7895_044d2200"
Output for 5.6.9
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1461717233.3444_4f0e35f6" string(28) "foo_1461717233.3445_75e1f8b6"
Output for 5.6.8
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1461917340.0148_5cecfc52" string(28) "foo_1461917340.0148_81fa4ace"
Output for 5.6.7
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1464115775.0175_e000dfa0" string(28) "foo_1464115775.0175_ec54e043"
Output for 5.5.35
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1463869269.8355_c47180de" string(28) "foo_1463869269.8356_b6e423c0"
Output for 5.5.34
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1460298483.4217_f88eee7d" string(28) "foo_1460298483.4218_1c7b4822"
Output for 5.5.33
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(27) "foo_1457433542.314_d12eb1ef" string(28) "foo_1457433542.3141_785d78fd"
Output for 5.5.32
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1458145146.0378_9135f296" string(28) "foo_1458145146.0379_f506f9a2"
Output for 5.5.31
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1458458342.6978_be598a5f" string(28) "foo_1458458342.6978_11ba1b76"
Output for 5.5.30
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1459443362.3435_512abcdc" string(28) "foo_1459443362.3435_049b7ce8"
Output for 5.5.29
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1460806044.0316_57e315ac" string(28) "foo_1460806044.0316_139118f3"
Output for 5.5.28
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(27) "foo_1461159768.432_2883e20c" string(27) "foo_1461159768.432_3589101c"
Output for 5.5.27
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1461255425.9729_13603211" string(27) "foo_1461255425.973_07b72c11"
Output for 5.5.26
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1461620543.6667_9cc4b5f0" string(28) "foo_1461620543.6667_98aef73b"
Output for 5.5.25
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1461815417.6193_5dfe4ffa" string(28) "foo_1461815417.6193_db575b64"
Output for 5.5.24
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1462015367.5831_49e0ac00" string(28) "foo_1462015367.5832_814eeed2"
Output for 5.4.45
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1447325503.5384_f34a2472" string(28) "foo_1447325503.5384_7618c039"
Output for 5.4.44
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1447325504.8573_bf305643" string(28) "foo_1447325504.8574_6b6586ef"
Output for 5.4.43
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1447325506.3003_379d6c0e" string(28) "foo_1447325506.3003_cbbff89b"
Output for 5.4.42
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1447325507.0857_6d2db282" string(28) "foo_1447325507.0857_aa19e3ba"
Output for 5.4.41
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1447325507.4723_b098f3f5" string(28) "foo_1447325507.4723_fdc9998f"
Output for 5.4.40
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1447325508.5216_d9f0038d" string(28) "foo_1447325508.5217_bac98629"
Output for 5.4.39
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1447325509.1638_61b64840" string(28) "foo_1447325509.1638_3f9857bb"
Output for 5.4.38
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1447325509.5277_74b15974" string(28) "foo_1447325509.5278_6f609eae"
Output for 5.4.37
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1447325510.3733_1acb052b" string(28) "foo_1447325510.3733_13620584"
Output for 5.4.36
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1447325510.5991_cb4a9680" string(28) "foo_1447325510.5991_e2e5580c"
Output for 5.4.35
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1447325511.1071_7147f7d2" string(28) "foo_1447325511.1072_b046b3b0"
Output for 5.4.34
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(27) "foo_1447325511.877_ea1c7407" string(28) "foo_1447325511.8771_d3208280"
Output for 5.4.32
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1447325512.8165_8fdce659" string(28) "foo_1447325512.8166_9d27cf92"
Output for 5.4.31
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1447325513.1421_c8247a68" string(28) "foo_1447325513.1422_f68ed9e7"
Output for 5.4.30
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1447325513.6671_57d8614e" string(28) "foo_1447325513.6672_5e964e69"
Output for 5.4.29
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1447325513.8585_6c89c257" string(28) "foo_1447325513.8585_0d03b52e"
Output for 5.4.28
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1447325514.1933_dd4a935c" string(28) "foo_1447325514.1933_f08f18b1"
Output for 5.4.27
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1447325514.5343_91cbee4e" string(28) "foo_1447325514.5343_28e3e189"
Output for 5.4.26
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1447325514.8713_127c132d" string(28) "foo_1447325514.8713_4ee73961"
Output for 5.4.25
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1447325515.2157_3a3e6b54" string(28) "foo_1447325515.2157_48d58e78"
Output for 5.4.24
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1447325515.7447_8299dbe7" string(28) "foo_1447325515.7447_10b72463"
Output for 5.4.23
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1447325515.9085_66557745" string(28) "foo_1447325515.9085_cebbf07f"
Output for 5.4.22
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1447325516.6095_f704f114" string(28) "foo_1447325516.6096_88888356"
Output for 5.4.21
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1447325516.7777_17210730" string(28) "foo_1447325516.7777_7133438d"
Output for 5.4.20
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1447325517.1179_3b1e6a9a" string(28) "foo_1447325517.1179_3dd0a60c"
Output for 5.4.19
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1447325517.6277_f2715e1c" string(28) "foo_1447325517.6278_9305752f"
Output for 5.4.18
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1447325517.9718_420deb0e" string(28) "foo_1447325517.9718_dd461c3c"
Output for 5.4.17
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1447325518.4493_40eb3d1e" string(28) "foo_1447325518.4494_98dbaa6f"
Output for 5.4.16
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1447325518.8097_96318bed" string(28) "foo_1447325518.8098_7c590631"
Output for 5.4.15
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1447325519.0825_29bfd476" string(28) "foo_1447325519.0825_978540b6"
Output for 5.4.14
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(27) "foo_1447325519.492_28837ace" string(27) "foo_1447325519.492_00f1c029"
Output for 5.4.13
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1447325519.7654_edc1f906" string(28) "foo_1447325519.7654_2b6a180f"
Output for 5.4.12
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1447325520.0739_55e9eeba" string(28) "foo_1447325520.0739_1e4ef2c9"
Output for 5.4.11
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1447325520.5427_c85c3e2f" string(28) "foo_1447325520.5428_3c71655d"
Output for 5.4.10
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1447325520.8497_1c36e6e9" string(28) "foo_1447325520.8497_b42d84e0"
Output for 5.4.9
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1447325521.0315_f57844f1" string(28) "foo_1447325521.0315_0c222660"
Output for 5.4.8
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1447325521.4529_cba375f2" string(28) "foo_1447325521.4529_02110be7"
Output for 5.4.7
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1447325521.7079_79638e88" string(28) "foo_1447325521.7079_f0a4e0dd"
Output for 5.4.6
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1447325521.9229_87a38828" string(28) "foo_1447325521.9229_959fab77"
Output for 5.4.5
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1447325522.3101_1f26648e" string(28) "foo_1447325522.3101_3520a6c4"
Output for 5.4.4
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1447325522.5767_ed6be2df" string(28) "foo_1447325522.5767_c63edcd5"
Output for 5.4.3
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1447325522.7322_b2690843" string(28) "foo_1447325522.7322_023cf695"
Output for 5.4.2
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1447325523.2018_84efd6bb" string(28) "foo_1447325523.2018_0d6fff46"
Output for 5.4.1
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(28) "foo_1447325523.4658_b938f4bc" string(28) "foo_1447325523.4658_93fb417a"
Output for 5.4.0
Warning: assert(): Assertion failed in /in/BaGmh on line 56 string(27) "foo_1447325523.604_579da519" string(27) "foo_1447325523.604_6e268d50"
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/BaGmh on line 50
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/BaGmh 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/BaGmh 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/BaGmh 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/BaGmh on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/BaGmh on line 3
Process exited with code 255.