3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Bijective { public $dictionary = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; public function __construct() { $this->dictionary = str_split($this->dictionary); var_dump($this->dictionary); } public function encode($i) { if ($i == 0) return $this->dictionary[0]; $result = ''; $base = count($this->dictionary); while ($i > 0) { $result[] = $this->dictionary[($i % $base)]; $i = floor($i / $base); } var_dump($result); $result = array_reverse($result); var_dump($result); return join("", $result); } public function decode($input) { $i = 0; $base = count($this->dictionary); $input = str_split($input); foreach($input as $char) { $pos = array_search($char, $this->dictionary); $i = $i * $base + $pos; } return $i; } } $bj = new Bijective(); $hash = $bj->encode($bj->decode('Abc') + 1); var_dump($hash);
Output for git.master, git.master_jit, rfc.property-hooks
array(62) { [0]=> string(1) "a" [1]=> string(1) "b" [2]=> string(1) "c" [3]=> string(1) "d" [4]=> string(1) "e" [5]=> string(1) "f" [6]=> string(1) "g" [7]=> string(1) "h" [8]=> string(1) "i" [9]=> string(1) "j" [10]=> string(1) "k" [11]=> string(1) "l" [12]=> string(1) "m" [13]=> string(1) "n" [14]=> string(1) "o" [15]=> string(1) "p" [16]=> string(1) "q" [17]=> string(1) "r" [18]=> string(1) "s" [19]=> string(1) "t" [20]=> string(1) "u" [21]=> string(1) "v" [22]=> string(1) "w" [23]=> string(1) "x" [24]=> string(1) "y" [25]=> string(1) "z" [26]=> string(1) "A" [27]=> string(1) "B" [28]=> string(1) "C" [29]=> string(1) "D" [30]=> string(1) "E" [31]=> string(1) "F" [32]=> string(1) "G" [33]=> string(1) "H" [34]=> string(1) "I" [35]=> string(1) "J" [36]=> string(1) "K" [37]=> string(1) "L" [38]=> string(1) "M" [39]=> string(1) "N" [40]=> string(1) "O" [41]=> string(1) "P" [42]=> string(1) "Q" [43]=> string(1) "R" [44]=> string(1) "S" [45]=> string(1) "T" [46]=> string(1) "U" [47]=> string(1) "V" [48]=> string(1) "W" [49]=> string(1) "X" [50]=> string(1) "Y" [51]=> string(1) "Z" [52]=> string(1) "0" [53]=> string(1) "1" [54]=> string(1) "2" [55]=> string(1) "3" [56]=> string(1) "4" [57]=> string(1) "5" [58]=> string(1) "6" [59]=> string(1) "7" [60]=> string(1) "8" [61]=> string(1) "9" } Fatal error: Uncaught Error: [] operator not supported for strings in /in/5ETbX:23 Stack trace: #0 /in/5ETbX(51): Bijective->encode(100009) #1 {main} thrown in /in/5ETbX on line 23
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
64.1 ms | 403 KiB | 8 Q