php-doc-en/appendices/migration81/new-features.xml
Laurent VOULLEMIER 64b3b8a362
Fix unpacking with string key example
The example seems not relevant since it already works and produces the same output in the previous PHP versions.

Closes GH-1501.
2022-04-04 12:29:44 +02:00

491 lines
14 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<sect1 xml:id="migration81.new-features" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>New Features</title>
<sect2 xml:id="migration81.new-features.core">
<title>PHP Core</title>
<sect3 xml:id="migration81.new-features.core.octal-literal-prefix">
<title>Integer Octal Literal Prefix</title>
<para>
Octal integers can now use an explicit
<literal>0o</literal>/<literal>0O</literal>
prefix in integer literals,
similarly to binary and hexadecimal integer literals.
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
014; // Non-prefix octal literal
0o14; // Prefixed octal literal
?>
]]>
</programlisting>
</informalexample>
</para>
<!-- RFC: https://wiki.php.net/rfc/explicit_octal_notation -->
</sect3>
<sect3 xml:id="migration81.new-features.core.unpacking-string-keys">
<title>Array Unpacking with String Keys</title>
<para>
Added support for <link linkend="language.types.array.unpacking">array unpacking with strings keys</link>.
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$arr1 = [1, 'a' => 'b'];
$arr2 = [...$arr1, 'c' => 'd']; //[1, 'a' => 'b', 'c' => 'd']
?>
]]>
</programlisting>
</informalexample>
</para>
<!-- RFC: https://wiki.php.net/rfc/array_unpacking_string_keys -->
</sect3>
<sect3 xml:id="migration81.new-features.core.named-arg-after-unpack">
<title>Named Argument After Argument Unpacking</title>
<para>
It is now possible to specify named arguments after an argument unpack.
<!-- TODO Add an example -->
e.g.
foo(...$args, named: $arg).
</para>
</sect3>
<sect3 xml:id="migration81.new-features.core.upload-full-path-key">
<title>full-path Key for File Uploads</title>
<para>
File uploads now provide an additional <literal>full_path</literal> key,
which contains the full path (rather than just the basename) of the uploaded file.
This is intended for use in conjunction with "upload webkitdirectory".
</para>
<!-- RFC: https://wiki.php.net/rfc/array_unpacking_string_keys -->
</sect3>
<sect3 xml:id="migration81.new-features.core.enums">
<title>Enumerations</title>
<para>
Support for <link linkend="language.enumerations">Enumerations</link> has been added.
<!-- RFC: https://wiki.php.net/rfc/enumerations -->
</para>
</sect3>
<sect3 xml:id="migration81.new-features.core.fibers">
<title>Fibers</title>
<para>
Support for <link linkend="language.fibers">Fibers</link> has been added.
<!-- RFC: https://wiki.php.net/rfc/fibers -->
</para>
</sect3>
<sect3 xml:id="migration81.new-features.core.callable-syntax">
<title>First Class Callable Syntax</title>
<para>
Closures for callables can now be created using <link linkend="functions.first_class_callable_syntax">the syntax <code>myFunc(...)</code></link>,
which is identical to <code>Closure::fromCallable('myFunc')</code>.
<!-- RFC: https://wiki.php.net/rfc/first_class_callable_syntax -->
</para>
<note>
<simpara>
The <code>...</code> is part of the syntax, and not an omission.
</simpara>
</note>
</sect3>
<sect3 xml:id="migration81.new-features.core.intersection-types">
<title>Intersection Types</title>
<para>
Support for <link linkend="language.types.declarations.composite.intersection">intersection types</link> has been added.
<!-- RFC: https://wiki.php.net/rfc/pure-intersection-types -->
</para>
<caution>
<simpara>
<link linkend="language.types.declarations.composite.intersection">
Intersection types</link> cannot be used together with
<link linkend="language.types.declarations.composite.union">
union types</link>
</simpara>
</caution>
</sect3>
<sect3 xml:id="migration81.new-features.core.never-type">
<title>Never type</title>
<para>
A new return only type &never; has been added.
This indicates that a function either <function>exit</function>,
throws an exception, or doesn't terminate.
<!-- RFC: https://wiki.php.net/rfc/noreturn_type -->
</para>
</sect3>
<sect3 xml:id="migration81.new-features.core.new-in-initializer">
<title>&new; in Initializers</title>
<para>
It is now possible to use <code>new ClassName()</code> expressions as the
default value of a parameter, static variable, global constant initializers,
and as attribute arguments.
Objects can also be passed to <function>define</function> now.
<!-- TODO Add an example -->
</para>
<!-- RFC: https://wiki.php.net/rfc/new_in_initializers -->
</sect3>
<sect3 xml:id="migration81.new-features.core.readonly">
<title>Readonly properties</title>
<para>
Support for <link linkend="language.oop5.properties.readonly-properties">readonly</link> has been added.
<!-- RFC: https://wiki.php.net/rfc/readonly_properties_v2 -->
</para>
</sect3>
<sect3 xml:id="migration81.new-features.core.final-constants">
<title>Final class constants</title>
<para>
Added support for <link linkend="language.oop5.final.example.php81">the <modifier>final</modifier> modifier for class constants</link>.
Also, interface constants become overridable by default.
<!-- RFC: https://wiki.php.net/rfc/final_class_const -->
</para>
</sect3>
</sect2>
<sect2 xml:id="migration81.new-features.curl">
<title>CURL</title>
<para>
Added the <constant>CURLOPT_DOH_URL</constant> option.
</para>
<para>
Added options for blob certificate when libcurl &gt;= 7.71.0:
</para>
<itemizedlist>
<listitem>
<simpara><constant>CURLOPT_ISSUERCERT_BLOB</constant></simpara>
</listitem>
<listitem>
<simpara><constant>CURLOPT_PROXY_ISSUERCERT</constant></simpara>
</listitem>
<listitem>
<simpara><constant>CURLOPT_PROXY_ISSUERCERT_BLOB</constant></simpara>
</listitem>
<listitem>
<simpara><constant>CURLOPT_PROXY_SSLCERT_BLOB</constant></simpara>
</listitem>
<listitem>
<simpara><constant>CURLOPT_PROXY_SSLKEY_BLOB</constant></simpara>
</listitem>
<listitem>
<simpara><constant>CURLOPT_SSLCERT_BLOB</constant></simpara>
</listitem>
<listitem>
<simpara><constant>CURLOPT_SSLKEY_BLOB</constant></simpara>
</listitem>
</itemizedlist>
<para>
Added <classname>CURLStringFile</classname>, which can be used to post
a file from a &string; rather than a file:
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$file = new CURLStringFile($data, 'filename.txt', 'text/plain');
curl_setopt($curl, CURLOPT_POSTFIELDS, ['file' => $file]);
?>
]]>
</programlisting>
</informalexample>
</para>
</sect2>
<sect2 xml:id="migration81.new-features.fpm">
<title>FPM</title>
<para>
Added openmetrics status format. It can be used by Prometheus to fetch FPM
metrics.
</para>
<para>
Added new pool option for the dynamic process manager called
<literal>pm.max_spawn_rate</literal>. It allows to start a number of children
at a faster rate when dynamic pm is selected.
The default value is <literal>32</literal> which was the previous
hard coded value.
</para>
</sect2>
<sect2 xml:id="migration81.new-features.gd">
<title>GD</title>
<para>
Avif support is now available through
<function>imagecreatefromavif</function> and
<function>imageavif</function>,
if libgd has been built with Avif support.
</para>
</sect2>
<sect2 xml:id="migration81.new-features.hash">
<title>Hash</title>
<para>
The following functions <function>hash</function>,
<function>hash_file</function>, and <function>hash_init</function>
now support an additional optional <parameter>options</parameter>
argument, which can be used to pass algorithm specific data.
</para>
<sect3 xml:id="migration81.new-features.hash.murmurhash3">
<title>MurmurHash3</title>
<para>
Added support for <literal>MurmurHash3</literal> with streaming
support. The following variants are implemented:
</para>
<itemizedlist>
<listitem>
<simpara>murmur3a, 32-bit hash</simpara>
</listitem>
<listitem>
<simpara>murmur3c, 128-bit hash for x86</simpara>
</listitem>
<listitem>
<simpara>murmur3f, 128-bit hash for x64</simpara>
</listitem>
</itemizedlist>
<para>
The initial hash state can be passed through the <literal>seed</literal>
key in the <parameter>options</parameter> array, for example:
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$h = hash("murmur3f", $data, options: ["seed" => 42]);
echo $h, "\n";
?>
]]>
</programlisting>
</informalexample>
A valid seed value is within the range from <literal>0</literal>
to the platform defined <constant>UINT_MAX</constant>, usually
<literal>4294967295</literal>.
</para>
</sect3>
<sect3 xml:id="migration81.new-features.hash.xxhash">
<title>xxHash</title>
<para>
Added support for <literal>xxHash</literal>.
The following variants are implemented:
</para>
<itemizedlist>
<listitem>
<simpara>xxh32, 32-bit hash</simpara>
</listitem>
<listitem>
<simpara>xxh64, 64-bit hash</simpara>
</listitem>
<listitem>
<simpara>xxh3, 64-bit hash</simpara>
</listitem>
<listitem>
<simpara>xxh128, 128-bit hash</simpara>
</listitem>
</itemizedlist>
<para>
The initial hash state can be passed through the <literal>seed</literal>
key in the <parameter>options</parameter> array, for example:
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$h = hash("xxh3", $data, options: ["seed" => 42]);
echo $h, "\n";
?>
]]>
</programlisting>
</informalexample>
Secret usage is supported through passing the <literal>secret</literal>
key in the <parameter>options</parameter> array, too:
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$h = hash("xxh3", $data, options: ["secret" => "at least 136 bytes long secret here"]);
echo $h, "\n";
?>
]]>
</programlisting>
</informalexample>
The quality of the custom secret is crucial for the quality of the resulting hash.
It is highly recommended for the secret to use the best possible entropy.
</para>
</sect3>
</sect2>
<sect2 xml:id="migration81.new-features.mysqli">
<title>MySQLi</title>
<sect3 xml:id="migration81.new-features.mysqli.local_infile_directory">
<title>New INI directive <literal>mysqli.local_infile_directory</literal></title>
<para>
The <link linkend="ini.mysqli.local-infile-directory">mysqli.local_infile_directory</link>
INI directive has been added, which can be used to specify a directory from
which files are allowed to be loaded. It is only meaningful if
<link linkend="ini.mysqli.allow-local-infile">mysqli.allow_local_infile</link>
is not enabled, as all directories are allowed in that case.
</para>
</sect3>
<sect3 xml:id="migration81.new-features.mysqli.bind-in-execute">
<title>Binding parameters in execute</title>
<para>
It is now possible to bind parameters by passing them as an array to
<methodname>mysqli_stmt::execute</methodname>. All values will be bound as
strings. Only list arrays are allowed. This new feature is not available
when MySQLi is compiled with libmysqlclient.
<!-- RFC: https://wiki.php.net/rfc/mysqli_bind_in_execute -->
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$stmt = $mysqli->prepare('INSERT INTO users(id, name) VALUES(?,?)');
$stmt->execute([1, $username]);
?>
]]>
</programlisting>
</informalexample>
</para>
</sect3>
<sect3 xml:id="migration81.new-features.mysqli.mysqli_fetch_column">
<title>New method <methodname>mysqli_result::fetch_column</methodname></title>
<para>
<methodname>mysqli_result::fetch_column</methodname>
has been added to allow fetching a single scalar value from the result set.
The new method accepts an optional 0-based <parameter>column</parameter>
parameter of type &integer; specifying which column to fetch from.
<!-- RFC: https://wiki.php.net/rfc/mysqli_fetch_column -->
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$result = $mysqli->query('SELECT username FROM users WHERE id = 123');
echo $result->fetch_column();
?>
]]>
</programlisting>
</informalexample>
</para>
</sect3>
</sect2>
<sect2 xml:id="migration81.new-features.pdo_mysql">
<title>PDO</title>
<para>
The <constant>PDO::MYSQL_ATTR_LOCAL_INFILE_DIRECTORY</constant> attribute
has been added, which can be used to specify a directory from which files
are allowed to be loaded.
It is only meaningful if <constant>PDO::MYSQL_ATTR_LOCAL_INFILE</constant>
is not enabled, as all directories are allowed in that case.
</para>
</sect2>
<sect2 xml:id="migration81.new-features.pdo_sqlite">
<title>PDO_SQLite</title>
<para>
SQLite's <literal>"file:"</literal> DSN syntax is now supported,
which allows specifying additional flags.
This feature is not available if open_basedir is set.
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
new PDO('sqlite:file:path/to/sqlite.db?mode=ro')
?>
]]>
</programlisting>
</informalexample>
</para>
</sect2>
<sect2 xml:id="migration81.new-features.posix">
<title>POSIX</title>
<para>
Added <constant>POSIX_RLIMIT_KQUEUES</constant> and <constant>POSIX_RLIMIT_NPTS</constant>.
These rlimits are only available on FreeBSD.
</para>
</sect2>
<sect2 xml:id="migration81.new-features.standard">
<title>Standard</title>
<para>
<function>fputcsv</function> now accepts a new
<parameter>eol</parameter> argument which allows to define a custom
End of Line sequence, the default remains the same and is <literal>"\n"</literal>.
</para>
</sect2>
<sect2 xml:id="migration81.new-features.spl">
<title>SPL</title>
<para>
<methodname>SplFileObject::fputcsv</methodname> now accepts a new
<parameter>eol</parameter> argument which allows to define a custom
End of Line sequence, the default remains the same and is <literal>"\n"</literal>.
</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
-->