reference/misc/functions/pack.xml
7926717892c5129038097f8a1fa396e209837575
...
...
@@ -11,8 +11,7 @@
11
11
<methodsynopsis>
12
12
<type>string</type><methodname>pack</methodname>
13
13
<methodparam><type>string</type><parameter>format</parameter></methodparam>
14
-
<methodparam choice="opt"><type>mixed</type><parameter>args</parameter></methodparam>
15
-
<methodparam choice="opt"><type>mixed</type><parameter>...</parameter></methodparam>
14
+
<methodparam rep="repeat"><type>mixed</type><parameter>values</parameter></methodparam>
16
15
</methodsynopsis>
17
16
<para>
18
17
Pack given arguments into a binary string according to
...
...
@@ -138,10 +137,26 @@
138
137
<entry>float (machine dependent size and representation)</entry>
139
138
</row>
140
139
<row>
140
+
<entry>g</entry>
141
+
<entry>float (machine dependent size, little endian byte order)</entry>
142
+
</row>
143
+
<row>
144
+
<entry>G</entry>
145
+
<entry>float (machine dependent size, big endian byte order)</entry>
146
+
</row>
147
+
<row>
141
148
<entry>d</entry>
142
149
<entry>double (machine dependent size and representation)</entry>
143
150
</row>
144
151
<row>
152
+
<entry>e</entry>
153
+
<entry>double (machine dependent size, little endian byte order)</entry>
154
+
</row>
155
+
<row>
156
+
<entry>E</entry>
157
+
<entry>double (machine dependent size, big endian byte order)</entry>
158
+
</row>
159
+
<row>
145
160
<entry>x</entry>
146
161
<entry>NUL byte</entry>
147
162
</row>
...
...
@@ -151,7 +166,7 @@
151
166
</row>
152
167
<row>
153
168
<entry>Z</entry>
154
-
<entry>NUL-padded string (new in PHP 5.5)</entry>
169
+
<entry>NUL-padded string</entry>
155
170
</row>
156
171
<row>
157
172
<entry>@</entry>
...
...
@@ -164,7 +179,7 @@
164
179
</listitem>
165
180
</varlistentry>
166
181
<varlistentry>
167
-
<term><parameter>args</parameter></term>
182
+
<term><parameter>values</parameter></term>
168
183
<listitem>
169
184
<para>
170
185
</para>
...
...
@@ -194,16 +209,21 @@
194
209
</thead>
195
210
<tbody>
196
211
<row>
197
-
<entry>5.6.3</entry>
212
+
<entry>8.0.0</entry>
198
213
<entry>
199
-
The "q", "Q", "J" and "P" codes were added to enable working with 64-bit numbers.
214
+
This function no longer returns &false; on failure.
200
215
</entry>
201
216
</row>
202
217
<row>
203
-
<entry>5.5.0</entry>
218
+
<entry>7.2.0</entry>
204
219
<entry>
205
-
The "Z" code was added with equivalent functionality to "a" for Perl
206
-
compatibility.
220
+
<type>float</type> and <type>double</type> types supports both Big Endian and Little Endian.
221
+
</entry>
222
+
</row>
223
+
<row>
224
+
<entry>7.0.15,7.1.1</entry>
225
+
<entry>
226
+
The "e", "E", "g" and "G" codes were added to enable byte order support for float and double.
207
227
</entry>
208
228
</row>
209
229
</tbody>
...
...
@@ -235,25 +255,25 @@ $binarydata = pack("nvc*", 0x1234, 0x5678, 65, 66);
235
255
<refsect1 role="notes">
236
256
&reftitle.notes;
237
257
<caution>
238
-
<para>Note that PHP internally stores <type>integer</type> values as
258
+
<para>Note that PHP internally stores <type>int</type> values as
239
259
signed values of a machine-dependent size (C type <literal>long</literal>).
240
260
Integer literals and operations that yield numbers outside the bounds of the
241
-
<type>integer</type> type will be stored as <type>float</type>.
261
+
<type>int</type> type will be stored as <type>float</type>.
242
262
When packing these floats as integers, they are first cast into the integer
243
263
type. This may or may not result in the desired byte pattern.
244
264
</para>
245
265
<para>The most relevant case is when packing unsigned numbers that would
246
-
be representable with the <type>integer</type> type if it were unsigned.
247
-
In systems where the <type>integer</type> type has a 32-bit size, the cast
248
-
usually results in the same byte pattern as if the <type>integer</type> were
266
+
be representable with the <type>int</type> type if it were unsigned.
267
+
In systems where the <type>int</type> type has a 32-bit size, the cast
268
+
usually results in the same byte pattern as if the <type>int</type> were
249
269
unsigned (although this relies on implementation-defined unsigned to signed
250
270
conversions, as per the C standard). In systems where the
251
-
<type>integer</type> type has 64-bit size, the <type>float</type> most
271
+
<type>int</type> type has 64-bit size, the <type>float</type> most
252
272
likely does not have a mantissa large enough to hold the value without
253
273
loss of precision. If those systems also have a native 64-bit C
254
274
<literal>int</literal> type (most UNIX-like systems don't), the only way to
255
275
use the <literal>I</literal> pack format in the upper range is to create
256
-
<type>integer</type> negative values with the same byte representation
276
+
<type>int</type> negative values with the same byte representation
257
277
as the desired unsigned value.
258
278
</para>
259
279
</caution>
...
...
@@ -269,7 +289,6 @@ $binarydata = pack("nvc*", 0x1234, 0x5678, 65, 66);
269
289
</refsect1>
270
290
271
291
</refentry>
272
-

273
292
<!-- Keep this comment at the end of the file
274
293
Local variables:
275
294
mode: sgml
276
295