xref: /PHP-8.3/ext/standard/tests/strings/pack_Z.phpt (revision 6ec69d72)
1--TEST--
2pack()/unpack(): "Z" format
3--FILE--
4<?php
5var_dump(
6    pack("Z0", "f"),
7    pack("Z5", "foo\0"),
8    pack("Z4", "fooo"),
9    pack("Z4", "foo"),
10    pack("Z*", "foo"),
11    unpack("Z*", "foo\0\rbar\0 \t\r\n"),
12    unpack("Z9", "foo\0\rbar\0 \t\r\n"),
13    unpack("Z2", "\0"),
14    unpack("Z2", "\0\0"),
15    unpack("Z2", "A\0"),
16    unpack("Z2", "AB\0"),
17    unpack("Z2", "ABC")
18);
19?>
20--EXPECTF--
21Warning: unpack(): Type Z: not enough input values, need 2 values but only 1 was provided in %s on line %d
22string(0) ""
23string(5) "foo%c%c"
24string(4) "foo%c"
25string(4) "foo%c"
26string(4) "foo%c"
27array(1) {
28  [1]=>
29  string(3) "foo"
30}
31array(1) {
32  [1]=>
33  string(3) "foo"
34}
35bool(false)
36array(1) {
37  [1]=>
38  string(0) ""
39}
40array(1) {
41  [1]=>
42  string(1) "A"
43}
44array(1) {
45  [1]=>
46  string(2) "AB"
47}
48array(1) {
49  [1]=>
50  string(2) "AB"
51}
52