3v4l.org

run code in 300+ PHP versions simultaneously
<?php function gdr_encode($val) { $bin = ''; while ($val > 0) { $bin .= chr($val & 0xFF); $val >>= 8; } return str_replace(array('/', '='), array('_', ''), base64_encode($bin)); } function gdr_decode($str) { $bin = base64_decode(str_replace('_', '/', $str)); $val = 0; for ($i=strlen($bin)-1; $i>=0; $i--) { $val |= ord($bin[$i]) << $i*8; } return $val; } function test_enc($val) { $enc = gdr_encode($val); $dec = gdr_decode($enc); if ($val === $dec) { echo "$enc $val\n"; } else { echo "$enc $val ERROR: gdr_decode($enc) == $dec\n"; } } foreach (array(0, 1, 99, 100, 255, 256, 999, 1000, 9999, 10000, 65535, 65536, 99999, 100000, 999999, 1000000, 4294967295, 4294967296) as $val) { test_enc($val); }echo "\n"; /* // seed rng for consistent values if (phpversion() < '5.2.1') { die('old rng'); } mt_srand(42); for ($i=0; $i<63; $i++) { $val = 1<<$i; $val += mt_rand(0, $val/2); test_enc($val); } */
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught Error: Undefined constant " 65535" in /in/Q2IYF:31 Stack trace: #0 {main} thrown in /in/Q2IYF on line 31
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.25, 7.4.27 - 7.4.33
Warning: Use of undefined constant  65535 - assumed ' 65535' (this will throw an Error in a future version of PHP) in /in/Q2IYF on line 31 Warning: Use of undefined constant  65536 - assumed ' 65536' (this will throw an Error in a future version of PHP) in /in/Q2IYF on line 31 Warning: Use of undefined constant  4294967295 - assumed ' 4294967295' (this will throw an Error in a future version of PHP) in /in/Q2IYF on line 31 Warning: Use of undefined constant  4294967296 - assumed ' 4294967296' (this will throw an Error in a future version of PHP) in /in/Q2IYF on line 31 0 AQ 1 Yw 99 ZA 100 _w 255 AAE 256 5wM 999 6AM 1000 Dyc 9999 ECc 10000 Notice: Undefined variable: val ERROR in /in/Q2IYF on line 27 : gdr_decode() == 0 Notice: Undefined variable: val ERROR in /in/Q2IYF on line 27 : gdr_decode() == 0 n4YB 99999 oIYB 100000 P0IP 999999 QEIP 1000000 Notice: Undefined variable: val ERROR in /in/Q2IYF on line 27 : gdr_decode() == 0 Notice: Undefined variable: val ERROR in /in/Q2IYF on line 27 : gdr_decode() == 0
Output for 7.3.32 - 7.3.33, 7.4.26
Warning: Use of undefined constant  65535 - assumed ' 65535' (this will throw an Error in a future version of PHP) in /in/Q2IYF on line 31 Warning: Use of undefined constant  65536 - assumed ' 65536' (this will throw an Error in a future version of PHP) in /in/Q2IYF on line 31 Warning: Use of undefined constant  4294967295 - assumed ' 4294967295' (this will throw an Error in a future version of PHP) in /in/Q2IYF on line 31 Warning: Use of undefined constant  4294967296 - assumed ' 4294967296' (this will throw an Error in a future version of PHP) in /in/Q2IYF on line 31 0 AQ 1 Yw 99 ZA 100 _w 255 AAE 256 5wM 999 6AM 1000 Dyc 9999 ECc 10000 : gdr_decode() == 0 : gdr_decode() == 0 n4YB 99999 oIYB 100000 P0IP 999999 QEIP 1000000 : gdr_decode() == 0 : gdr_decode() == 0
Output for 5.0.4 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 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
Notice: Use of undefined constant  65535 - assumed ' 65535' in /in/Q2IYF on line 31 Notice: Use of undefined constant  65536 - assumed ' 65536' in /in/Q2IYF on line 31 Notice: Use of undefined constant  4294967295 - assumed ' 4294967295' in /in/Q2IYF on line 31 Notice: Use of undefined constant  4294967296 - assumed ' 4294967296' in /in/Q2IYF on line 31 0 AQ 1 Yw 99 ZA 100 _w 255 AAE 256 5wM 999 6AM 1000 Dyc 9999 ECc 10000 Notice: Undefined variable: val ERROR in /in/Q2IYF on line 27 : gdr_decode() == 0 Notice: Undefined variable: val ERROR in /in/Q2IYF on line 27 : gdr_decode() == 0 n4YB 99999 oIYB 100000 P0IP 999999 QEIP 1000000 Notice: Undefined variable: val ERROR in /in/Q2IYF on line 27 : gdr_decode() == 0 Notice: Undefined variable: val ERROR in /in/Q2IYF on line 27 : gdr_decode() == 0
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.3
Notice: Use of undefined constant  65535 - assumed ' 65535' in /in/Q2IYF on line 31 Notice: Use of undefined constant  65536 - assumed ' 65536' in /in/Q2IYF on line 31 Notice: Use of undefined constant  4294967295 - assumed ' 4294967295' in /in/Q2IYF on line 31 Notice: Use of undefined constant  4294967296 - assumed ' 4294967296' in /in/Q2IYF on line 31 0 AQ 1 Yw 99 ZA 100 _w 255 AAE 256 5wM 999 6AM 1000 Dyc 9999 ECc 10000 Notice: Undefined variable: val ERROR in /in/Q2IYF on line 27 : gdr_decode() == 0 Notice: Undefined variable: val ERROR in /in/Q2IYF on line 27 : gdr_decode() == 0 n4YB 99999 oIYB 100000 P0IP 999999 QEIP 1000000 Notice: Undefined variable: val ERROR in /in/Q2IYF on line 27 : gdr_decode() == 0 Notice: Undefined variable: val ERROR in /in/Q2IYF on line 27 : gdr_decode() == 0

preferences:
336.28 ms | 403 KiB | 459 Q