3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ProceduralNumericSequenceGenerator { private $algo, $state; public function __construct($seed = NULL, $algo = "sha256") { if ($seed === NULL) { $seed = time(); } if (array_search($algo, hash_algos()) === FALSE) { throw new RuntimeException("Hashing algorithm \"$algo\" is not available."); } $this->state = $seed; $this->algo = $algo; } public function getInt() { return hexdec(substr($this->state, 0, PHP_INT_SIZE)); } public function advance() { $this->state = hash($this->algo, $this->state); } public function advanceNew() { $new = clone $this; $new->advance(); return $new; } public function advanceAndGetInt() { $this->advance(); return $this->getInt(); } public function advanceNewAndGetInt() { $new = $this->advanceNew(); return [$new->getInt(), $new]; } } $rng = new ProceduralNumericSequenceGenerator(time()); var_dump($rng->advanceAndGetInt()); $rng2 = clone $rng; var_dump($rng->advanceAndGetInt()); var_dump($rng2->advanceAndGetInt());
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.26, 7.3.0 - 7.3.13, 7.4.0 - 7.4.1
int(728083863) int(3274895661) int(3274895661)
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/H1d3E on line 40
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/H1d3E on line 40
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/H1d3E on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/H1d3E on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/H1d3E on line 4
Process exited with code 255.

preferences:
61.29 ms | 1800 KiB | 4 Q