3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $tests = array('a', 'Z'); foreach ($tests as $packChar) { $packString = $packChar.'*'.$packChar.'*'.$packChar.'*'; $data = pack($packString, "foo", "bar", "baz"); echo "packed is: \n"; var_dump($data); $y = unpack('a3omg/a3lol/a3bbq' , $data ); echo "\nPHP 5.5 a\n"; var_dump($y); $y = unpack('Z3omg/Z3lol/Z3bbq' , $data ); echo "\nPHP 5.5 Z\n"; var_dump($y); }
Output for 5.5.0 - 7.1.0
packed is: string(9) "foobarbaz" PHP 5.5 a array(3) { ["omg"]=> string(3) "foo" ["lol"]=> string(3) "bar" ["bbq"]=> string(3) "baz" } PHP 5.5 Z array(3) { ["omg"]=> string(3) "foo" ["lol"]=> string(3) "bar" ["bbq"]=> string(3) "baz" } packed is: string(12) "foobarbaz" PHP 5.5 a array(3) { ["omg"]=> string(3) "foo" ["lol"]=> string(3) "ba" ["bbq"]=> string(3) "rb" } PHP 5.5 Z array(3) { ["omg"]=> string(3) "foo" ["lol"]=> string(0) "" ["bbq"]=> string(1) "r" }
Output for 4.4.8 - 4.4.9, 5.2.4 - 5.4.45
packed is: string(9) "foobarbaz" PHP 5.5 a array(3) { ["omg"]=> string(3) "foo" ["lol"]=> string(3) "bar" ["bbq"]=> string(3) "baz" } Warning: unpack(): Invalid format type Z in /in/jArjZ on line 17 PHP 5.5 Z bool(false) Warning: pack(): Type Z: unknown format code in /in/jArjZ on line 8 packed is: bool(false) Warning: unpack(): Type a: not enough input, need 3, have 0 in /in/jArjZ on line 13 PHP 5.5 a bool(false) Warning: unpack(): Invalid format type Z in /in/jArjZ on line 17 PHP 5.5 Z bool(false)
Output for 4.3.2 - 4.4.7, 5.0.0 - 5.2.3
packed is: string(9) "foobarbaz" PHP 5.5 a array(3) { ["omg"]=> string(3) "foo" ["lol"]=> string(3) "bar" ["bbq"]=> string(3) "baz" } PHP 5.5 Z array(0) { } Warning: pack(): Type Z: unknown format code in /in/jArjZ on line 8 packed is: bool(false) Warning: unpack(): Type a: not enough input, need 3, have 0 in /in/jArjZ on line 13 PHP 5.5 a bool(false) PHP 5.5 Z array(0) { }
Output for 4.3.0 - 4.3.1
packed is: string(9) "foobarbaz" PHP 5.5 a array(3) { ["omg"]=> string(3) "foo" ["lol"]=> string(3) "bar" ["bbq"]=> string(3) "baz" } PHP 5.5 Z array(0) { } Warning: pack() [http://www.php.net/function.pack]: Type Z: unknown format code in /in/jArjZ on line 8 packed is: bool(false) Warning: unpack() [http://www.php.net/function.unpack]: Type a: not enough input, need 3, have 0 in /in/jArjZ on line 13 PHP 5.5 a bool(false) PHP 5.5 Z array(0) { }