3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
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.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.1, 5.1.3 - 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.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