Beef up the notes on the PHP 5.5 changes to pack() and unpack().

Specifically, I've added changelogs to the function pages (not sure how I
missed that to start with), expanded the discussion of what the changes are,
and moved them into the backward incompatible changes page, since they are.


git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@329132 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Adam Harvey 2013-01-14 06:35:43 +00:00
parent cdb9df4c46
commit 55929e29ac
3 changed files with 134 additions and 14 deletions

View file

@ -90,6 +90,70 @@
</para>
</sect2>
<sect2 xml:id="migration55.incompatible.pack">
<title><function>pack</function> and <function>unpack</function> changes</title>
<para>
Changes were made to <function>pack</function> and
<function>unpack</function> to make them more compatible with Perl:
</para>
<itemizedlist>
<listitem>
<simpara>
<function>pack</function> now supports the "Z" format code, which
behaves identically to "a".
</simpara>
</listitem>
<listitem>
<simpara>
<function>unpack</function> now support the "Z" format code for NULL
padded strings, and behaves as "a" did in previous versions: it will
strip trailing NULL bytes.
</simpara>
</listitem>
<listitem>
<simpara>
<function>unpack</function> now keeps trailing NULL bytes when the "a"
format code is used.
</simpara>
</listitem>
<listitem>
<simpara>
<function>unpack</function> now strips all trailing ASCII whitespace
when the "A" format code is used.
</simpara>
</listitem>
</itemizedlist>
<para>
Writing backward compatible code that uses the "a" format code with
<function>unpack</function> requires the use of
<function>version_compare</function>, due to the backward compatibility
break.
</para>
<para>
For example:
</para>
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
// Old code:
$data = unpack('a5', $packed);
// New code:
if (version_compare(PHP_VERSION, '5.5.0-dev', '>=')) {
$data = unpack('Z5', $packed);
} else {
$data = unpack('a5', $packed);
}
?>
]]>
</programlisting>
</informalexample>
</sect2>
<sect2 xml:id="migration55.incompatible.guid">
<title>PHP logo GUIDs removed</title>
@ -418,20 +482,10 @@ String dereferencing: P
</listitem>
<listitem>
<simpara>
<function>pack</function> and <function>unpack</function> now support the
<literal>Z</literal> format character for null-padded strings.
</simpara>
</listitem>
<listitem>
<simpara>
<function>unpack</function>'s <literal>a</literal> format no longer
strips trailing null bytes, bringing it into line with Perl's behaviour.
</simpara>
</listitem>
<listitem>
<simpara>
<function>unpack</function>'s <literal>A</literal> format now strips all
trailing ASCII whitespace, bringing it into line with Perl's behaviour.
The behaviour of <function>pack</function> and
<function>unpack</function> with the "a" and "A" format codes has
changed.
<link linkend="migration55.incompatible.pack">Detailed notes on these changes are available.</link>
</simpara>
</listitem>
</itemizedlist>

View file

@ -133,6 +133,10 @@
<entry>X</entry>
<entry>Back up one byte</entry>
</row>
<row>
<entry>Z</entry>
<entry>NUL-padded string (new in PHP 5.5)</entry>
</row>
<row>
<entry>@</entry>
<entry>NUL-fill to absolute position</entry>
@ -161,6 +165,31 @@
</para>
</refsect1>
<refsect1 role="changelog"><!-- {{{ -->
&reftitle.changelog;
<para>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>5.5.0</entry>
<entry>
The "Z" code was added with equivalent functionality to "a" for Perl
compatibility.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</refsect1><!-- }}} -->
<refsect1 role="examples">
&reftitle.examples;
<para>

View file

@ -58,6 +58,43 @@
</para>
</refsect1>
<refsect1 role="changelog"><!-- {{{ -->
&reftitle.changelog;
<para>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>5.5.0</entry>
<entry>
<para>
Changes were made to bring this function into line with Perl:
</para>
<para>
The "a" code now retains trailing NULL bytes.
</para>
<para>
The "A" code now strips all trailing ASCII whitespace (spaces, tabs,
newlines, carriage returns, and NULL bytes).
</para>
<para>
The "Z" code was added for NULL-padded strings, and removes trailing
NULL bytes.
</para>
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</refsect1><!-- }}} -->
<refsect1 role="examples">
&reftitle.examples;
<para>