WordPress.org

Make WordPress Core

Opened 4 weeks ago

Last modified 5 days ago

#47783 new defect (bug)

PHP 7.4: Deprecations

Reported by: ayeshrajans Owned by:
Milestone: 5.3 Priority: normal
Severity: normal Version:
Component: General Keywords: has-patch php74
Focuses: coding-standards Cc:

Description

PHP 7.4 deprecates some functionalities, and Travis builds are currently not even completing properly due to the amount of warnings thrown.

We already have a few tickets (thanks to @jrfnl - 👏👏👏). I will post patches related to PHP 7.4 deprecation changes (https://wiki.php.net/rfc/deprecations_php_7_4) here.

Attachments (5)

47783-magic_quotes_deprecation-wp-core.patch (2.0 KB) - added by ayeshrajans 4 weeks ago.
47783-magic_quotes_deprecation-getid3.patch (1.2 KB) - added by ayeshrajans 4 weeks ago.
47783-magic_quotes_deprecation-phpmailer.patch (740 bytes) - added by ayeshrajans 4 weeks ago.
47783-magic_quotes_deprecation-wp-core--2.patch (2.3 KB) - added by ayeshrajans 4 weeks ago.
Replaces 47783-magic_quotes_deprecation-wp-core.patch. PHPDoc for map_deep() function is updated to reflect the changes.
47783-magic_quotes_deprecation-PclZip.patch (13.8 KB) - added by ayeshrajans 4 weeks ago.
Juliette - Thanks you are right PclZip was missing in the patches. This one does it, and it turned out to be a rather big patch because the library had 2 methods to disable and swam back magic quotes functionality. Since this class is from 2009, there is no access indivators. However, I decided to remove the methods themselves and the class property because they started with name priv in properties, and the class property wasn't used anywhere else.

Download all attachments as: .zip

Change History (17)

#1 @SergeyBiryukov
4 weeks ago

Related:

#47704
PHP 7.4: Fix issues regarding accessing null/bool/etc as if they were an array
#47746
PHP 7.4 compatibility fix / implode argument order
#47751
PHP 7.4 compatibility fix / accessing arrays/string using curly brace syntax
#47783
PHP 7.4: Deprecations


#2 @jrf
4 weeks ago

Another related ticket:

  • #47441 PHP 7.4: use of deprecated operator precedence

Travis builds are currently not even completing properly due to the amount of warnings thrown

This is due to the commits related to PHP 7.4 deprecations having gone in this Monday.

All other issues from before then have already been addressed in the above tickets, including patching up external dependencies.

Note: as the related external dependencies have not (yet) released new versions, those dependencies in core have not been updated yet.
See the above mentioned tickets, most notably #47746 and #47751

A scan with the bleeding edge version of the PHPCompatibility scanner - i.e. including the open PRs #844 and #847 - should be able to detect most issues as all the sniffs regarding PHP deprecations which can be detected with a static scanner, have already been written.

Last edited 4 weeks ago by jrf (previous) (diff)

#3 @ayeshrajans
4 weeks ago

PHP 7.4 deprecates get_magic_quotes_gpc and get_magic_quotes_runtime. This was long due, and there are few issues in Trac about removing this functionality. Historically, those bits were there because we supported PHP 5.2-5.4, when magic quotes were being used in the wild.

With WordPress no longer supporting PHP versions < 5.6, we can now remove these checks completely.

There are 3 patches following this comment:

1. Fixes in WordPress core: 47783-magic_quotes_deprecation-wp-core.patch

This fixes all magic quote calls in core.

2. Fixes in external libs: Getid3: 47783-magic_quotes_deprecation-getid3.patch

This has come up in other tickets, and I think we can follow the same conclusion in other tickets whether we maintain our fork, or try to push upstream to update.

3. Fixes in external libs: PHPMaier: 47783-magic_quotes_deprecation-phpmailer.patch

PHPMailer is an active project, so I opened a PR https://github.com/PHPMailer/PHPMailer/pull/1794 with the same patch. We are using v5.2.2, although latest version is 5.2.7 in upstream.

#4 @ayeshrajans
4 weeks ago

Thanks @jrf - I was watching those tickets, and except for 3 instances in wordpress-importer plugin, all tests pass with your patches 👍. Thank you.

Current Travis build on 7.4snapshot: https://travis-ci.org/Ayesh/wordpress-develop/jobs/564094819

Last edited 4 weeks ago by ayeshrajans (previous) (diff)

#5 @jrf
4 weeks ago

getID3 is also an active project and has already accepted patches regarding the curly braces issue: https://github.com/JamesHeinrich/getID3

except for 3 instances in wordpress-importer plugin, all tests passes with your patches

The WordPress Importer issue the Core unit tests are running into has been fixed downstream already, there is just no new release yet: https://github.com/WordPress/wordpress-importer/pull/53

Other than that: if you want to keep track of how ready PHPCompatibility is, follow this ticket: #808

#6 @jrf
4 weeks ago

Reviewed 47783-magic_quotes_deprecation-wp-core.patch and looks sane to me.

get_magic_quotes_gpc() will always return false on PHP 5.4+, so removing the conditions related to this completely is the right course of action.


Reviewed 47783-magic_quotes_deprecation-getid3.patch and looks sane to me.


Reviewed 47783-magic_quotes_deprecation-phpmailer.patch and IMO, all references to magic quotes in the encodeFile() function can be removed as get_magic_quotes_runtime() will always return false on PHP 5.4+.
I.e.:

  • The code line now touched + the whole condition block below it.
  • The condition block a few lines further down.

PHPMailer currently has a minimum PHP requirement of PHP 5.5.0, so these changes can be safely made.


Refs:

#7 follow-up: @ayeshrajans
4 weeks ago

  • Keywords has-patch added

Thank you.
In the PHPMailer patch PHP_VERSION_ID < 70400 is supposed to prevent the get_magic_quotes_runtime() function from being called (so avoid the the deprecation notice), and still keep the $magic_quotes variable false. The idea was to not remove the $magic_quotes variable and two de-slash if blocks below it.

PHPMailer 5.2-stable branch doesn't show a lot of activity, so I tried to keep the PR as minimal as possible. This branch also supports PHP >= 5.0.0 (https://github.com/PHPMailer/PHPMailer/blob/5.2-stable/composer.json#L24). Only 6.x versions require PHP 5.5 minimum, and magic_quotes functionality is gone in those versions.

#8 in reply to: ↑ 7 ; follow-up: @jrf
4 weeks ago

  • Focuses coding-standards added

Replying to ayeshrajans:

Thank you.
In the PHPMailer patch PHP_VERSION_ID < 70400 is supposed to prevent the get_magic_quotes_runtime() function from being called (so avoid the the deprecation notice), and still keep the $magic_quotes variable false. The idea was to not remove the $magic_quotes variable and two de-slash if blocks below it.

PHPMailer 5.2-stable branch doesn't show a lot of activity, so I tried to keep the PR as minimal as possible. This branch also supports PHP >= 5.0.0 (https://github.com/PHPMailer/PHPMailer/blob/5.2-stable/composer.json#L24). Only 6.x versions require PHP 5.5 minimum, and magic_quotes functionality is gone in those versions.

In that case, as the minimum PHP version for WP is now 5.6, the PHPMailer patch should not be necessary and we should just upgrade PHPMailer to v 6.x.

#9 @jrf
4 weeks ago

I've done a quick scan and - while already silenced - it looks like the wp-admin/includes/class-plzip.php file, which is also an external dependency, also contains some magic quote related code round lines 5341/5345/5376.

#10 @SergeyBiryukov
4 weeks ago

  • Milestone changed from Awaiting Review to 5.3

@ayeshrajans
4 weeks ago

Replaces 47783-magic_quotes_deprecation-wp-core.patch. PHPDoc for map_deep() function is updated to reflect the changes.

@ayeshrajans
4 weeks ago

Juliette - Thanks you are right PclZip was missing in the patches. This one does it, and it turned out to be a rather big patch because the library had 2 methods to disable and swam back magic quotes functionality. Since this class is from 2009, there is no access indivators. However, I decided to remove the methods themselves and the class property because they started with name priv in properties, and the class property wasn't used anywhere else.

#11 @jrf
3 weeks ago

  • Keywords php74 added

#12 in reply to: ↑ 8 @chesio
5 days ago

Replying to jrf:

In that case, as the minimum PHP version for WP is now 5.6, the PHPMailer patch should not be necessary and we should just upgrade PHPMailer to v 6.x.

Related: #40472, #41750 and #45822

Last edited 5 days ago by chesio (previous) (diff)
Note: See TracTickets for help on using tickets.