3v4l.org

run code in 300+ PHP versions simultaneously
<?php function showRawCharacters($result) { $resultInHex = unpack('H*', $result); $resultInHex = $resultInHex[1]; $resultSeparated = implode(', ', str_split($resultInHex, 2)); echo $resultSeparated; } $tests = array('a', 'Z'); foreach ($tests as $packChar) { $packString = $packChar.'*'.$packChar.'*'.$packChar.'*'; echo "Packing with: ".$packString."\n"; $data = pack($packString, "foo", "bar", "baz"); echo "packed is: \n"; showRawCharacters($data); $y = unpack('Z3omg/Z3lol/Z3bbq' , $data ); echo "\nPHP 5.5 Z\n"; var_dump($y); }
Output for 5.5.0 - 5.5.36, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Packing with: a*a*a* packed is: 66, 6f, 6f, 62, 61, 72, 62, 61, 7a PHP 5.5 Z array(3) { ["omg"]=> string(3) "foo" ["lol"]=> string(3) "bar" ["bbq"]=> string(3) "baz" } Packing with: Z*Z*Z* packed is: 66, 6f, 6f, 00, 62, 61, 72, 00, 62, 61, 7a, 00 PHP 5.5 Z array(3) { ["omg"]=> string(3) "foo" ["lol"]=> string(0) "" ["bbq"]=> string(1) "r" }
Output for 5.2.4 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45
Packing with: a*a*a* packed is: 66, 6f, 6f, 62, 61, 72, 62, 61, 7a Warning: unpack(): Invalid format type Z in /in/dQKJ8 on line 22 PHP 5.5 Z bool(false) Packing with: Z*Z*Z* Warning: pack(): Type Z: unknown format code in /in/dQKJ8 on line 17 packed is: Warning: unpack(): Invalid format type Z in /in/dQKJ8 on line 22 PHP 5.5 Z bool(false)
Output for 5.0.0 - 5.0.2, 5.0.5, 5.1.0 - 5.1.1, 5.1.3 - 5.1.6, 5.2.0 - 5.2.3
Packing with: a*a*a* packed is: 66, 6f, 6f, 62, 61, 72, 62, 61, 7a PHP 5.5 Z array(0) { } Packing with: Z*Z*Z* Warning: pack(): Type Z: unknown format code in /in/dQKJ8 on line 17 packed is: PHP 5.5 Z array(0) { }
Output for 5.1.2
Packing with: a*a*a* packed is: 66, 6f, 6f, 62, 61, 72, 62, 61, 7a, 0 PHP 5.5 Z array(0) { } Packing with: Z*Z*Z* Warning: pack(): Type Z: unknown format code in /in/dQKJ8 on line 17 packed is: 0 PHP 5.5 Z array(0) { }
Output for 5.0.3 - 5.0.4
Packing with: a*a*a* packed is: Warning: unpack(): Type H: outside of string in /in/dQKJ8 on line 4 66, 6f, 6f, 62, 61, 72, 62, 61, 7a PHP 5.5 Z array(0) { } Packing with: Z*Z*Z* Warning: pack(): Type Z: unknown format code in /in/dQKJ8 on line 17 packed is: Warning: unpack(): Type H: outside of string in /in/dQKJ8 on line 4 PHP 5.5 Z array(0) { }
Output for 4.4.5 - 4.4.9
Packing with: a*a*a* packed is: Fatal error: Call to undefined function: str_split() in /in/dQKJ8 on line 6
Process exited with code 255.
Output for 4.3.5 - 4.3.9, 4.3.11, 4.4.0 - 4.4.4
Packing with: a*a*a* packed is: Fatal error: Call to undefined function: str_split() in /in/dQKJ8 on line 6
Process exited with code 255.
Output for 4.3.10
Packing with: a*a*a* packed is: Warning: unpack(): Type H: outside of string in /in/dQKJ8 on line 4 Fatal error: Call to undefined function: str_split() in /in/dQKJ8 on line 6
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Packing with: a*a*a* packed is: Notice: Undefined offset: 1 in /in/dQKJ8 on line 5 Fatal error: Call to undefined function: str_split() in /in/dQKJ8 on line 6
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Packing with: a*a*a* packed is: Notice: Undefined offset: 1 in /in/dQKJ8 on line 5 Fatal error: Call to undefined function: str_split() in /in/dQKJ8 on line 6

preferences:
259.61 ms | 402 KiB | 392 Q