-
Notifications
You must be signed in to change notification settings - Fork 880
PHP 8.0 migration guide #170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
0dcce7a
PHP 8.0 migration guide
cmb69 dc84e0d
Fold XMP-RPC removal into incompatible changes section
cmb69 08f07a4
Fix grammar
cmb69 21fdc49
Explicitly list deprecated pgsql function aliases and replacements
cmb69 d4dd0a6
Move resource to object conversions into own section
cmb69 eb5836c
Elaborate
cmb69 81f9ee1
Address some of Nikita's review comments
cmb69 287c8d5
Incorporate further suggestions from Nikita
cmb69 0f71a05
Avoid linking to wrong WeakMap class
cmb69 0efb45a
Incorporate more of Nikita's suggestions
cmb69 fab4967
Add example for iterating over ZipArchive entries
cmb69 5c6c863
Enclose PHP code snippet in <?php … ?> tags
cmb69 3cc6d9c
Declaring custom assert() is no longer allowed
cmb69 bea7624
Fix function name
cmb69 4657e64
Incorporate more of Nikita's suggestions
cmb69 1bf3e16
Incorporate more of Nikita's suggestions
cmb69 2dbd795
Merge special pages for constants, functions and methods into new-fea…
cmb69 79547e3
Move info to appropriate sections
cmb69 43c4890
Add note that imagedestroy() no longer has an effect
cmb69 35ab87e
The (real) cast has been removed
cmb69 ea698e9
Link to union types section
cmb69 5dc520a
Add subsections for the most important changes
cmb69 4619753
Integrate Windows specific changes into incompatible section
cmb69 57c0bed
Link to match expression section
cmb69 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <!-- $Revision: 348018 $ --> | ||
|
|
||
| <appendix xml:id="migration80" xmlns="http://docbook.org/ns/docbook" xmlns:phd="http://www.php.net/ns/phd"> | ||
| <title>Migrating from PHP 7.4.x to PHP 8.0.x</title> | ||
|
|
||
| &appendices.migration80.new-features; | ||
| &appendices.migration80.incompatible; | ||
| &appendices.migration80.deprecated; | ||
| &appendices.migration80.other-changes; | ||
|
|
||
| <sect1 phd:chunk="false" xml:id="migration80.intro"> | ||
| <para> | ||
| This new major version brings with it a number of | ||
| <link linkend="migration80.new-features">new features</link> and | ||
| <link linkend="migration80.incompatible">some incompatibilities</link> | ||
| that should be tested for before switching PHP versions in production | ||
| environments. | ||
| </para> | ||
|
|
||
| <para> | ||
| &manual.migration.seealso; | ||
| <link linkend="migration70">7.0.x</link>, | ||
| <link linkend="migration71">7.1.x</link>, | ||
| <link linkend="migration72">7.2.x</link>, | ||
| <link linkend="migration73">7.3.x</link>. | ||
| <link linkend="migration74">7.4.x</link>. | ||
| </para> | ||
| </sect1> | ||
| </appendix> | ||
|
|
||
| <!-- 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 | ||
| --> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,258 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <!-- $Revision: 348038 $ --> | ||
|
|
||
| <sect1 xml:id="migration80.deprecated"> | ||
| <title>Deprecated Features</title> | ||
|
|
||
| <sect2 xml:id="migration80.deprecated.core"> | ||
| <title>PHP Core</title> | ||
|
|
||
| <itemizedlist> | ||
| <listitem> | ||
| <para> | ||
| If a parameter with a default value is followed by a required parameter, the default value has | ||
| no effect. This is deprecated as of PHP 8.0.0 and can generally be resolved by dropping the | ||
| default value, without a change in functionality: | ||
| </para> | ||
| <para> | ||
| <programlisting role="php"> | ||
| <![CDATA[ | ||
| <?php | ||
| function test($a = [], $b) {} // Before | ||
| function test($a, $b) {} // After | ||
| ?> | ||
| ]]> | ||
| </programlisting> | ||
| </para> | ||
| <para> | ||
| One exception to this rule are parameters of the form <code>Type $param = null</code>, where | ||
| the null default makes the type implicitly nullable. This usage remains allowed, but it is | ||
| recommended to use an explicit nullable type instead: | ||
| </para> | ||
| <para> | ||
| <programlisting role="php"> | ||
| <![CDATA[ | ||
| <?php | ||
| function test(A $a = null, $b) {} // Still allowed | ||
| function test(?A $a, $b) {} // Recommended | ||
| ?> | ||
| ]]> | ||
| </programlisting> | ||
| </para> | ||
| </listitem> | ||
| <listitem> | ||
| <para> | ||
| Calling <function>get_defined_functions</function> with <parameter>exclude_disabled</parameter> | ||
| explicitly set to &false; is deprecated and no longer has an effect. | ||
| <function>get_defined_functions</function> will never include disabled functions. | ||
| </para> | ||
| </listitem> | ||
| </itemizedlist> | ||
| </sect2> | ||
|
|
||
| <sect2 xml:id="migration80.deprecated.enchant"> | ||
| <title>Enchant</title> | ||
|
|
||
| <itemizedlist> | ||
| <listitem> | ||
| <para> | ||
| <function>enchant_broker_set_dict_path</function> and | ||
| <function>enchant_broker_get_dict_path</function> | ||
| are deprecated, because that functionality is neither available in libenchant < 1.5 nor in | ||
| libenchant-2. | ||
| </para> | ||
| </listitem> | ||
| <listitem> | ||
| <para> | ||
| <function>enchant_dict_add_to_personal</function> is deprecated; use | ||
| <function>enchant_dict_add</function> instead. | ||
| </para> | ||
| </listitem> | ||
| <listitem> | ||
| <para> | ||
| <function>enchant_dict_is_in_session</function> is deprecated; use | ||
| <function>enchant_dict_is_added</function> instead. | ||
| </para> | ||
| </listitem> | ||
| <listitem> | ||
| <para> | ||
| <function>enchant_broker_free</function> and <function>enchant_broker_free_dict</function> are | ||
| deprecated; unset the object instead. | ||
| </para> | ||
| </listitem> | ||
| <listitem> | ||
| <para> | ||
| The <constant>ENCHANT_MYSPELL</constant> and <constant>ENCHANT_ISPELL</constant> constants are | ||
| deprecated. | ||
| </para> | ||
| </listitem> | ||
| </itemizedlist> | ||
| </sect2> | ||
|
|
||
| <sect2 xml:id="migration80.deprecated.libxml"> | ||
| <title>LibXML</title> | ||
|
|
||
| <para> | ||
| <function>libxml_disable_entity_loader</function> has been deprecated. As libxml 2.9.0 is now | ||
| required, external entity loading is guaranteed to be disabled by default, and this function is | ||
| no longer needed to protect against XXE attacks. | ||
| </para> | ||
| </sect2> | ||
|
|
||
| <sect2 xml:id="migration80.deprecated.pgsql"> | ||
| <title>PGSQL / PDO PGSQL</title> | ||
|
|
||
| <itemizedlist> | ||
| <listitem> | ||
| <para> | ||
| The constant <constant>PG_VERSION_STR</constant> now has the same value as | ||
| <constant>PG_VERSION</constant>, and thus is deprecated. | ||
| </para> | ||
| </listitem> | ||
| <listitem> | ||
| <para> | ||
| Function aliases in the pgsql extension have been deprecated. | ||
| See the following list for which functions should be used instead: | ||
| </para> | ||
| <para> | ||
| <simplelist> | ||
| <member><function>pg_errormessage</function> → <function>pg_last_error</function></member> | ||
| <member><function>pg_numrows</function> → <function>pg_num_rows</function></member> | ||
| <member><function>pg_numfields</function> → <function>pg_num_fields</function></member> | ||
| <member><function>pg_cmdtuples</function> → <function>pg_affected_rows</function></member> | ||
| <member><function>pg_fieldname</function> → <function>pg_field_name</function></member> | ||
| <member><function>pg_fieldsize</function> → <function>pg_field_size</function></member> | ||
| <member><function>pg_fieldtype</function> → <function>pg_field_type</function></member> | ||
| <member><function>pg_fieldnum</function> → <function>pg_field_num</function></member> | ||
| <member><function>pg_result</function> → <function>pg_fetch_result</function></member> | ||
| <member><function>pg_fieldprtlen</function> → <function>pg_field_prtlen</function></member> | ||
| <member><function>pg_fieldisnull</function> → <function>pg_field_is_null</function></member> | ||
| <member><function>pg_freeresult</function> → <function>pg_free_result</function></member> | ||
| <member><function>pg_getlastoid</function> → <function>pg_last_oid</function></member> | ||
| <member><function>pg_locreate</function> → <function>pg_lo_create</function></member> | ||
| <member><function>pg_lounlink</function> → <function>pg_lo_unlink</function></member> | ||
| <member><function>pg_loopen</function> → <function>pg_lo_open</function></member> | ||
| <member><function>pg_loclose</function> → <function>pg_lo_close</function></member> | ||
| <member><function>pg_loread</function> → <function>pg_lo_read</function></member> | ||
| <member><function>pg_lowrite</function> → <function>pg_lo_write</function></member> | ||
| <member><function>pg_loreadall</function> → <function>pg_lo_read_all</function></member> | ||
| <member><function>pg_loimport</function> → <function>pg_lo_import</function></member> | ||
| <member><function>pg_loexport</function> → <function>pg_lo_export</function></member> | ||
| <member><function>pg_setclientencoding</function> → <function>pg_set_client_encoding</function></member> | ||
| <member><function>pg_clientencoding</function> -> <function>pg_client_encoding</function></member> | ||
| </simplelist> | ||
| </para> | ||
| </listitem> | ||
| </itemizedlist> | ||
| </sect2> | ||
|
|
||
| <sect2 xml:id="migration80.deprecated.standard"> | ||
| <title>Standard Library</title> | ||
|
|
||
| <itemizedlist> | ||
| <listitem> | ||
| <para> | ||
| Sort comparison functions that return &true; or &false; will now throw a deprecation warning, and | ||
| should be replaced with an implementation that returns an integer less than, equal to, or greater | ||
| than zero. | ||
| </para> | ||
| <para> | ||
| <programlisting role="php"> | ||
| <![CDATA[ | ||
| <?php | ||
| // Replace | ||
| usort($array, fn($a, $b) => $a > $b); | ||
| // With | ||
| usort($array, fn($a, $b) => $a <=> $b); | ||
| ?> | ||
| ]]> | ||
| </programlisting> | ||
| </para> | ||
| </listitem> | ||
| </itemizedlist> | ||
| </sect2> | ||
|
|
||
| <sect2 xml:id="migration80.deprecated.zip"> | ||
| <title>Zip</title> | ||
|
|
||
| <itemizedlist> | ||
| <listitem> | ||
| <para> | ||
| Using an empty file as ZipArchive is deprecated. Libzip 1.6.0 does not accept empty files as | ||
| valid zip archives any longer. The existing workaround will be removed in the next version. | ||
| </para> | ||
| </listitem> | ||
| <listitem> | ||
| <para> | ||
| The procedural API of Zip is deprecated. Use <classname>ZipArchive</classname> instead. | ||
| Iteration over all entries can be accomplished using <methodname>ZipArchive::statIndex</methodname> | ||
| and a <link linkend="control-structures.for">for</link> loop: | ||
| </para> | ||
| <para> | ||
| <programlisting role="php"> | ||
| <![CDATA[ | ||
| <?php | ||
| // iterate using the procedural API | ||
| assert(is_resource($zip)); | ||
| while ($entry = zip_read($zip)) { | ||
| echo zip_entry_name($entry); | ||
| } | ||
|
|
||
| // iterate using the object-oriented API | ||
| assert($zip instanceof ZipArchive); | ||
| for ($i = 0; $entry = $zip->statIndex($i); $i++) { | ||
| echo $entry['name']; | ||
| } | ||
| ?> | ||
| ]]> | ||
| </programlisting> | ||
| </para> | ||
| </listitem> | ||
| </itemizedlist> | ||
| </sect2> | ||
|
|
||
| <sect2 xml:id="migration80.deprecated.reflection"> | ||
| <title>Reflection</title> | ||
|
|
||
| <itemizedlist> | ||
| <listitem> | ||
| <para> | ||
| <methodname>ReflectionFunction::isDisabled</methodname> is deprecated, as it is no longer | ||
| possible to create a <classname>ReflectionFunction</classname> for a disabled function. This | ||
| method now always returns &false;. | ||
| </para> | ||
| </listitem> | ||
| <listitem> | ||
| <para> | ||
| <methodname>ReflectionParameter::getClass</methodname>, | ||
| <methodname>ReflectionParameter::isArray</methodname>, and | ||
| <methodname>ReflectionParameter::isCallable</methodname> are deprecated. | ||
| <methodname>ReflectionParameter::getType</methodname> and the | ||
| <classname>ReflectionType</classname> APIs should be used instead. | ||
| </para> | ||
| </listitem> | ||
| </itemizedlist> | ||
| </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 | ||
| --> | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.