mirror of
https://github.com/php/doc-en.git
synced 2026-03-23 23:32:18 +01:00
647 lines
19 KiB
XML
647 lines
19 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
|
|
<sect1 xml:id="migration71.incompatible">
|
|
<title>Backward incompatible changes</title>
|
|
|
|
<sect2 xml:id="migration71.incompatible.too-few-arguments-exception">
|
|
<title>Throw on passing too few function arguments</title>
|
|
|
|
<para>
|
|
Previously, a warning would be emitted for invoking user-defined functions
|
|
with too few arguments. Now, this warning has been promoted to an Error
|
|
exception. This change only applies to user-defined functions, not internal
|
|
functions. For example:
|
|
</para>
|
|
|
|
<informalexample>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
function test($param){}
|
|
test();
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs.similar;
|
|
<screen>
|
|
<![CDATA[
|
|
Fatal error: Uncaught ArgumentCountError: Too few arguments to function test(), 0 passed in %s on line %d and exactly 1 expected in %s:%d
|
|
]]>
|
|
</screen>
|
|
</informalexample>
|
|
</sect2>
|
|
|
|
<sect2 xml:id="migration71.incompatible.forbid-dynamic-calls-to-scope-introspection-functions">
|
|
<title>Forbid dynamic calls to scope introspection functions</title>
|
|
|
|
<para>
|
|
Dynamic calls for certain functions have been forbidden (in the form of
|
|
<literal>$func()</literal> or <literal>array_map('extract', ...)</literal>,
|
|
etc). These functions either inspect or modify another scope, and present
|
|
with them ambiguous and unreliable behavior. The functions are as follows:
|
|
</para>
|
|
|
|
<itemizedlist>
|
|
<listitem>
|
|
<simpara>
|
|
<function>assert</function> - with a string as the first argument
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
<function>compact</function>
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
<function>extract</function>
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
<function>func_get_args</function>
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
<function>func_get_arg</function>
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
<function>func_num_args</function>
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
<function>get_defined_vars</function>
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
<function>mb_parse_str</function> - with one arg
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
<function>parse_str</function> - with one arg
|
|
</simpara>
|
|
</listitem>
|
|
</itemizedlist>
|
|
|
|
<informalexample>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
(function () {
|
|
$func = 'func_num_args';
|
|
$func();
|
|
})();
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
Warning: Cannot call func_num_args() dynamically in %s on line %d
|
|
]]>
|
|
</screen>
|
|
</informalexample>
|
|
</sect2>
|
|
|
|
<sect2 xml:id="migration71.incompatible.invalid-class-names">
|
|
<title>Invalid class, interface, and trait names</title>
|
|
|
|
<para>
|
|
The following names cannot be used to name classes, interfaces, or traits:
|
|
</para>
|
|
|
|
<itemizedlist>
|
|
<listitem>
|
|
<simpara><type>void</type></simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara><type>iterable</type></simpara>
|
|
</listitem>
|
|
</itemizedlist>
|
|
</sect2>
|
|
|
|
<sect2 xml:id="migration71.incompatible.numerical-strings-scientific-notation">
|
|
<title>Numerical string conversions now respect scientific notation</title>
|
|
|
|
<para>
|
|
Integer operations and conversions on numerical strings now respect
|
|
scientific notation. This also includes the <literal>(int)</literal> cast
|
|
operation, and the following functions: <function>intval</function> (where
|
|
the base is 10), <function>settype</function>, <function>decbin</function>,
|
|
<function>decoct</function>, and <function>dechex</function>.
|
|
</para>
|
|
</sect2>
|
|
|
|
<sect2 xml:id="migration71.incompatible.fixes-to-mt_rand-algorithm">
|
|
<title>Fixes to <function>mt_rand</function> algorithm</title>
|
|
|
|
<para>
|
|
<function>mt_rand</function> will now default to using the fixed version of
|
|
the Mersenne Twister algorithm. If deterministic output from
|
|
<function>mt_rand</function> was relied upon, then
|
|
<constant>MT_RAND_PHP</constant> can be used as optional second parameter
|
|
to <function>mt_srand</function> to preserve the old (incorrect)
|
|
implementation.
|
|
</para>
|
|
</sect2>
|
|
|
|
<sect2 xml:id="migration71.incompatible.rand-srand-aliases">
|
|
<title>
|
|
<function>rand</function> aliased to <function>mt_rand</function> and
|
|
<function>srand</function> aliased to <function>mt_srand</function>
|
|
</title>
|
|
|
|
<para>
|
|
<function>rand</function> and <function>srand</function> have now been made
|
|
aliases to <function>mt_rand</function> and <function>mt_srand</function>,
|
|
respectively. This means that the output for the following functions have
|
|
changed: <function>rand</function>, <function>shuffle</function>,
|
|
<function>str_shuffle</function>, and <function>array_rand</function>.
|
|
</para>
|
|
</sect2>
|
|
|
|
<sect2 xml:id="migration71.incompatible.delete-control-character-in-identifiers">
|
|
<title>Disallow the ASCII delete control character in identifiers</title>
|
|
|
|
<para>
|
|
The ASCII delete control character (<literal>0x7F</literal>) can no longer
|
|
be used in identifiers that are not quoted.
|
|
</para>
|
|
</sect2>
|
|
|
|
<sect2 xml:id="migration71.incompatible.error_log-syslog">
|
|
<title>
|
|
<parameter>error_log</parameter> changes with <literal>syslog</literal>
|
|
value
|
|
</title>
|
|
|
|
<para>
|
|
If the <parameter>error_log</parameter> ini setting is set to
|
|
<literal>syslog</literal>, the PHP error levels are mapped to the syslog
|
|
error levels. This brings finer differentiation in the error logs in
|
|
contrary to the previous approach where all the errors are logged with the
|
|
notice level only.
|
|
</para>
|
|
</sect2>
|
|
|
|
<sect2 xml:id="migration71.incompatible.dont-call-destructors">
|
|
<title>Do not call destructors on incomplete objects</title>
|
|
|
|
<para>
|
|
Destructors are now never called for objects that throw an exception during
|
|
the execution of their constructor. In previous versions this behavior
|
|
depended on whether the object was referenced outside the constructor (e.g.
|
|
by an exception backtrace).
|
|
</para>
|
|
</sect2>
|
|
|
|
<sect2 xml:id="migration71.incompatible.call_user_func-with-ref-args">
|
|
<title>
|
|
<function>call_user_func</function> handling of reference arguments
|
|
</title>
|
|
|
|
<para>
|
|
<function>call_user_func</function> will now always generate a warning
|
|
upon calls to functions that expect references as arguments. Previously
|
|
this depended on whether the call was fully qualified.
|
|
</para>
|
|
<para>
|
|
Additionally, <function>call_user_func</function> and
|
|
<function>call_user_func_array</function> will no longer abort the function
|
|
call in this case. The "expected reference" warning will be emitted, but the
|
|
call will proceed as usual.
|
|
</para>
|
|
</sect2>
|
|
|
|
<sect2 xml:id="migration71.incompatible.empty-string-index-operator">
|
|
<title>
|
|
The empty index operator is not supported for strings anymore
|
|
</title>
|
|
|
|
<para>
|
|
Applying the empty index operator to a string (e.g. <literal>$str[] = $x</literal>)
|
|
throws a fatal error instead of converting silently to array.
|
|
</para>
|
|
</sect2>
|
|
|
|
<sect2 xml:id="migration71.incompatible.empty-string-modifcation-by-character">
|
|
<title>Assignment via string index access on an empty string</title>
|
|
<para>
|
|
String modification by character on an empty string now works like for non-empty
|
|
strings, i.e. writing to an out of range offset pads the string with spaces,
|
|
where non-integer types are converted to integer, and only the first character of
|
|
the assigned string is used. Formerly, empty strings where silently treated like
|
|
an empty array.
|
|
<informalexample>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$a = '';
|
|
$a[10] = 'foo';
|
|
var_dump($a);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs.70;
|
|
<screen>
|
|
<![CDATA[
|
|
array(1) {
|
|
[10]=>
|
|
string(3) "foo"
|
|
}
|
|
]]>
|
|
</screen>
|
|
&example.outputs.71;
|
|
<screen>
|
|
<![CDATA[
|
|
string(11) " f"
|
|
]]>
|
|
</screen>
|
|
</informalexample>
|
|
</para>
|
|
</sect2>
|
|
|
|
<sect2 xml:id="migration71.incompatible.removed-ini-directives">
|
|
<title>Removed ini directives</title>
|
|
|
|
<para>
|
|
The following ini directives have been removed:
|
|
</para>
|
|
|
|
<itemizedlist>
|
|
<listitem>
|
|
<simpara>
|
|
<parameter>session.entropy_file</parameter>
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
<parameter>session.entropy_length</parameter>
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
<parameter>session.hash_function</parameter>
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
<parameter>session.hash_bits_per_character</parameter>
|
|
</simpara>
|
|
</listitem>
|
|
</itemizedlist>
|
|
</sect2>
|
|
|
|
<sect2 xml:id="migration71.incompatible.array-order">
|
|
<title>
|
|
Array ordering when elements are automatically created during by reference
|
|
assignments has changed
|
|
</title>
|
|
|
|
<para>
|
|
The order of the elements in an array has changed when those elements have
|
|
been automatically created by referencing them in a by reference
|
|
assignment. For example:
|
|
</para>
|
|
|
|
<informalexample>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$array = [];
|
|
$array["a"] =& $array["b"];
|
|
$array["b"] = 1;
|
|
var_dump($array);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs.70;
|
|
<screen>
|
|
<![CDATA[
|
|
array(2) {
|
|
["a"]=>
|
|
&int(1)
|
|
["b"]=>
|
|
&int(1)
|
|
}
|
|
]]>
|
|
</screen>
|
|
&example.outputs.71;
|
|
<screen>
|
|
<![CDATA[
|
|
array(2) {
|
|
["b"]=>
|
|
&int(1)
|
|
["a"]=>
|
|
&int(1)
|
|
}
|
|
]]>
|
|
</screen>
|
|
</informalexample>
|
|
</sect2>
|
|
|
|
<sect2 xml:id="migration71.incompatible.sort-order">
|
|
<title>Sort order of equal elements</title>
|
|
<para>
|
|
The internal sorting algorithm has been improved, what may result in
|
|
different sort order of elements, which compare as equal, than before.
|
|
</para>
|
|
<note>
|
|
<para>
|
|
Don't rely on the order of elements which compare as equal; it might change
|
|
anytime.
|
|
</para>
|
|
</note>
|
|
</sect2>
|
|
|
|
<sect2 xml:id="migration71.incompatible.e-recoverable">
|
|
<title>Error message for E_RECOVERABLE errors</title>
|
|
<para>
|
|
The error message for E_RECOVERABLE errors has been changed from "Catchable
|
|
fatal error" to "Recoverable fatal error".
|
|
</para>
|
|
</sect2>
|
|
|
|
<sect2 xml:id="migration71.incompatible.unserialize">
|
|
<title>$options parameter of unserialize()</title>
|
|
<para>
|
|
The <literal>allowed_classes</literal> element of the $options parameter of
|
|
<function>unserialize</function> is now strictly typed, i.e. if anything
|
|
other than an <type>array</type> or a <type>bool</type> is given,
|
|
unserialize() returns &false; and issues an <constant>E_WARNING</constant>.
|
|
</para>
|
|
</sect2>
|
|
|
|
<sect2 xml:id="migration71.incompatible.datetime-microseconds">
|
|
<title>DateTime constructor incorporates microseconds</title>
|
|
<para>
|
|
<classname>DateTime</classname> and <classname>DateTimeImmutable</classname>
|
|
now properly incorporate microseconds when constructed from the current time,
|
|
either explicitly or with a relative string (e.g. <literal>"first day of next
|
|
month"</literal>). This means that naive comparisons of two newly created
|
|
instances will now more likely return &false; instead of &true;:
|
|
<informalexample>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
new DateTime() == new DateTime();
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</informalexample>
|
|
</para>
|
|
</sect2>
|
|
|
|
<sect2 xml:id="migration71.incompatible.fatal-errors-to-error-exceptions">
|
|
<title>Fatal errors to <classname>Error</classname> exceptions conversions</title>
|
|
<para>
|
|
In the Date extension, invalid serialization data for
|
|
<classname>DateTime</classname> or <classname>DatePeriod</classname> classes,
|
|
or timezone initialization failure from serialized data, will now throw an
|
|
<classname>Error</classname> exception from the
|
|
<methodname>__wakeup</methodname> or <methodname>__set_state</methodname>
|
|
methods, instead of resulting in a fatal error.
|
|
</para>
|
|
|
|
<para>
|
|
In the DBA extension, data modification functions (such as
|
|
<function>dba_insert</function>) will now throw an
|
|
<classname>Error</classname> exception instead of triggering a catchable
|
|
fatal error if the key does not contain exactly two elements.
|
|
</para>
|
|
|
|
<para>
|
|
In the DOM extension, invalid schema or RelaxNG validation contexts will now
|
|
throw an <classname>Error</classname> exception instead of resulting in a
|
|
fatal error. Similarly, attempting to register a node class that does not
|
|
extend the appropriate base class, or attempting to read an invalid property
|
|
or write to a readonly property, will also now throw an
|
|
<classname>Error</classname> exception.
|
|
</para>
|
|
|
|
<para>
|
|
In the IMAP extension, email addresses longer than 16385 bytes will throw an
|
|
<classname>Error</classname> exception instead of resulting in a fatal error.
|
|
</para>
|
|
|
|
<para>
|
|
In the Intl extension, failing to call the parent constructor in a class
|
|
extending <classname>Collator</classname> before invoking the parent methods
|
|
will now throw an <classname>Error</classname> instead of resulting in a
|
|
recoverable fatal error. Also, cloning a
|
|
<classname>Transliterator</classname> object will now throw an
|
|
<classname>Error</classname> exception on failure to clone the internal
|
|
transliterator instead of resulting in a fatal error.
|
|
</para>
|
|
|
|
<para>
|
|
In the LDAP extension, providing an unknown modification type to
|
|
<function>ldap_batch_modify</function> will now throw an
|
|
<classname>Error</classname> exception instead of resulting in a fatal error.
|
|
</para>
|
|
|
|
<para>
|
|
In the mbstring extension, the <function>mb_ereg</function> and
|
|
<function>mb_eregi</function> functions will now throw a
|
|
<classname>ParseError</classname> exception if an invalid PHP expression is
|
|
provided and the 'e' option is used.
|
|
</para>
|
|
|
|
<para>
|
|
In the Mcrypt extension, the <function>mcrypt_encrypt</function> and
|
|
<function>mcrypt_decrypt</function> will now throw an
|
|
<classname>Error</classname> exception instead of resulting in a fatal error
|
|
if mcrypt cannot be initialized.
|
|
</para>
|
|
|
|
<para>
|
|
In the mysqli extension, attempting to read an invalid property or write to
|
|
a readonly property will now throw an <classname>Error</classname> exception
|
|
instead of resulting in a fatal error.
|
|
</para>
|
|
|
|
<para>
|
|
In the Reflection extension, failing to retrieve a reflection object or
|
|
retrieve an object property will now throw an <classname>Error</classname>
|
|
exception instead of resulting in a fatal error.
|
|
</para>
|
|
|
|
<para>
|
|
In the Session extension, custom session handlers that do not return strings
|
|
for session IDs will now throw an <classname>Error</classname> exception
|
|
instead of resulting in a fatal error when a function is called that must
|
|
generate a session ID.
|
|
</para>
|
|
|
|
<para>
|
|
In the SimpleXML extension, creating an unnamed or duplicate attribute will
|
|
now throw an <classname>Error</classname> exception instead of resulting in
|
|
a fatal error.
|
|
</para>
|
|
|
|
<para>
|
|
In the SPL extension, attempting to clone an
|
|
<classname>SplDirectory</classname> object will now throw an
|
|
<classname>Error</classname> exception instead of resulting in a fatal
|
|
error. Similarly, calling <methodname>ArrayIterator::append</methodname> when
|
|
iterating over an object will also now throw an <classname>Error</classname>
|
|
exception.
|
|
</para>
|
|
|
|
<para>
|
|
In the standard extension, the <function>assert</function> function, when
|
|
provided with a string argument as its first parameter, will now throw a
|
|
<classname>ParseError</classname> exception instead of resulting in a
|
|
catchable fatal error if the PHP code is invalid. Similarly, calling
|
|
<function>forward_static_call</function> outside of a class scope will now
|
|
throw an <classname>Error</classname> exception.
|
|
</para>
|
|
|
|
<para>
|
|
In the Tidy extension, creating a <classname>tidyNode</classname> manually
|
|
will now throw an <classname>Error</classname> exception instead of
|
|
resulting in a fatal error.
|
|
</para>
|
|
|
|
<para>
|
|
In the WDDX extension, a circular reference when serializing will now throw
|
|
an <classname>Error</classname> exception instead of resulting in a fatal
|
|
error.
|
|
</para>
|
|
|
|
<para>
|
|
In the XML-RPC extension, a circular reference when serializing will now
|
|
throw an instance of <classname>Error</classname> exception instead of
|
|
resulting in a fatal error.
|
|
</para>
|
|
|
|
<para>
|
|
In the Zip extension, the <methodname>ZipArchive::addGlob</methodname>
|
|
method will now throw an <classname>Error</classname> exception instead of
|
|
resulting in a fatal error if glob support is not available.
|
|
</para>
|
|
</sect2>
|
|
|
|
<sect2 xml:id="migration71.incompatible.lexical-names">
|
|
<title>Lexically bound variables cannot reuse names</title>
|
|
|
|
<para>
|
|
Variables bound to a <link linkend="functions.anonymous">closure</link> via
|
|
the <literal>use</literal> construct cannot use the same name as any
|
|
&link.superglobals;, <varname>$this</varname>, or any parameter. For
|
|
example, all of these function definition will result in a fatal error:
|
|
|
|
<informalexample>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$f = function () use ($_SERVER) {};
|
|
$f = function () use ($this) {};
|
|
$f = function ($param) use ($param) {};
|
|
]]>
|
|
</programlisting>
|
|
</informalexample>
|
|
</para>
|
|
</sect2>
|
|
|
|
<sect2 xml:id="migration71.incompatible.long2ip">
|
|
<title>long2ip() parameter type change</title>
|
|
<para>
|
|
<function>long2ip</function> now expects an <type>int</type> instead of a
|
|
<type>string</type>.
|
|
</para>
|
|
</sect2>
|
|
|
|
<sect2 xml:id="migration71.incompatible.json">
|
|
<title>JSON encoding and decoding</title>
|
|
<para>
|
|
The <parameter>serialize_precision</parameter> ini setting now controls the
|
|
serialization precision when encoding <type>float</type>s.
|
|
</para>
|
|
<para>
|
|
Decoding an empty key now results in an empty property name, rather than
|
|
<literal>_empty_</literal> as a property name.
|
|
|
|
<informalexample>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
var_dump(json_decode(json_encode(['' => 1])));
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs.similar;
|
|
<screen>
|
|
<![CDATA[
|
|
object(stdClass)#1 (1) {
|
|
[""]=>
|
|
int(1)
|
|
}
|
|
]]>
|
|
</screen>
|
|
</informalexample>
|
|
</para>
|
|
<para>
|
|
When supplying the <constant>JSON_UNESCAPED_UNICODE</constant> flag to
|
|
<function>json_encode</function>, the sequences U+2028 and U+2029 are now
|
|
escaped.
|
|
</para>
|
|
</sect2>
|
|
|
|
<sect2 xml:id="migration71.incompatible.mbstring">
|
|
<title>
|
|
Changes to <function>mb_ereg</function> and <function>mb_eregi</function>
|
|
parameter semantics
|
|
</title>
|
|
<para>
|
|
The third parameter to the <function>mb_ereg</function> and
|
|
<function>mb_eregi</function> functions (<parameter>regs</parameter>) will now be
|
|
set to an empty array if nothing was matched. Formerly, the parameter would
|
|
not have been modified.
|
|
</para>
|
|
</sect2>
|
|
|
|
<sect2 xml:id="migration71.incompatible.openssl">
|
|
<title>Drop support for the sslv2 stream</title>
|
|
<para>
|
|
The sslv2 stream has now been dropped in OpenSSL.
|
|
</para>
|
|
</sect2>
|
|
|
|
<sect2 xml:id="migration71.incompatible.typed-returns-compile-time">
|
|
<title>Forbid "return;" for typed returns already at compile-time</title>
|
|
<para>
|
|
Return statements without argument in functions which declare a return type
|
|
now trigger <constant>E_COMPILE_ERROR</constant> (unless the return type is
|
|
declared as <type>void</type>), even if the return statement would never be
|
|
reached.
|
|
</para>
|
|
</sect2>
|
|
|
|
</sect1>
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|