WordPress.org

Make WordPress Core

Opened 4 months ago

Closed 2 months ago

Last modified 5 weeks ago

#47751 closed defect (bug) (fixed)

PHP 7.4 compatibility fix / accessing arrays/string using curly brace syntax

Reported by: jrf Owned by: jorbin
Milestone: 5.3 Priority: normal
Severity: normal Version:
Component: General Keywords: has-patch has-unit-tests php74 has-dev-note
Focuses: coding-standards Cc:
PR Number:

Description

PHP used to allow both square brackets and curly braces to be used interchangeably for accessing array elements and string offsets.

<?php
$array = [1, 2];
echo $array[1]; // prints 2
echo $array{1}; // also prints 2
 
$string = "foo";
echo $string[0]; // prints "f"
echo $string{0}; // also prints "f"

The curly bracket syntax is only allowed in a limited set of cases and can be confusing for people not used to it.

PHP 7.4 will now deprecate the curly brace syntax for accessing array elements and string offsets and it is expected that support will be completely removed in PHP 8.0.

Ref: https://wiki.php.net/rfc/deprecate_curly_braces_array_access

The patches

A recent Travis build against the current trunk already shows unit tests failing because of the deprecation errors being thrown on PHP 7.4: https://travis-ci.com/WordPress/wordpress-develop/jobs/218044529

The WordPress code-base containes 182 instances of curly brace array access.

These 182 can be divided into issues in WP native files and in files from four external dependencies:

# Files # Issues
WP native files 4 11
PemFTP 1 2
POP3 1 1
Services_JSON 1 40
getID3 7 128

Similar to #47746, while the issues in external dependencies should be solved there, this may not be a feasible road.

PemFTP

I have not been able to find references to the canonical location where this code is publicly maintained, nor has a search of typical source repositories yielded anything.

The canonical URL mentioned in the file docblock points to PHPClasses where the code hasn't been updated for over 10 years.

With that in mind, I very much doubt there will be a new release any time soon.

POP3

I have not been able to find references to the canonical location where this code is publicly maintained, nor has a search of typical source repositories yielded anything.

Based on the file docblock, this external dependency hasn't been updated since 2011.

If anyone can point me to where this code is maintained, please do.

Services_JSON

I have not been able to find references to the canonical location where this code is publicly maintained, nor has a search of typical source repositories yielded anything.

The canonical URL mentioned in the file docblock points to a proposal on PEAR where the code hasn't been updated for over 14 years.

As this essentially has been added to PHP core anyway, I doubt there will be a publicly maintained canonical version of this code.

Related #47699

getID3

Now, as for the worst offender... there is a public and actively maintained GitHub repo available.

My pull request containing the fixes for getID3 has already been merged.

But...

  1. It is unclear when the next version will be released.
  2. WordPress currently includes version 1.9.14-201706111222 (June 2017), while the latest release is version 1.9.17, released February this year and version 2.0 is already in alpha.

So a decision would need to be taken about updating the dependency once the next version is released.

Conclusion

Based on the above, I will be uploading patches for all instances of the issue, though I will split the patches based on the code origin.

Like I've said in https://core.trac.wordpress.org/ticket/47746#comment:3 :

So, yes, while I agree that the fixes should primarily be made upstream, I don't think WP should be throwing deprecation notices when run on PHP 7.4 while we are waiting for
1) new releases from upstream and
2) the existing WP Core versions of those libraries to be updated.

A passing build on a branch containing all the patches can be found here: https://travis-ci.org/jrfnl/wordpress-develop/builds/561922102

These patches should cover all instances of this issue in the current codebase.
Based on the current trunk in combination with these patches, there are no remaining issues.

Other notes

Should there be a guideline in the WordPress Coding Standards Handbook that curly braces for array access should not be used ?

And if so, maybe now is the time to have another look at #46152, as the next version of PHPCompatibility will contain a sniff to detect these issues.

/cc @pento

Attachments (6)

47751-WP-native-files.patch (3.4 KB) - added by jrf 4 months ago.
[WP native files] PHP 7.4 compatibility: fix deprecated curly brace array access
47751-External-PemFTP.patch (1.0 KB) - added by jrf 4 months ago.
[External PemFTP] PHP 7.4 compatibility: fix deprecated curly brace array access
47751-External-Services_JSON.patch (12.5 KB) - added by jrf 4 months ago.
[External Services_JSON] PHP 7.4 compatibility: fix deprecated curly brace array access
47751-External-POP3.patch (1.0 KB) - added by jrf 4 months ago.
[External POP3] PHP 7.4 compatibility: fix deprecated curly brace array access
47751-External-getID3.patch (28.0 KB) - added by jrf 4 months ago.
[External getID3] PHP 7.4 compatibility: fix deprecated curly brace array access
47751-remaining-getid3.diff (1.1 KB) - added by desrosj 2 months ago.

Download all attachments as: .zip

Change History (20)

@jrf
4 months ago

[WP native files] PHP 7.4 compatibility: fix deprecated curly brace array access

@jrf
4 months ago

[External PemFTP] PHP 7.4 compatibility: fix deprecated curly brace array access

@jrf
4 months ago

[External Services_JSON] PHP 7.4 compatibility: fix deprecated curly brace array access

@jrf
4 months ago

[External POP3] PHP 7.4 compatibility: fix deprecated curly brace array access

@jrf
4 months ago

[External getID3] PHP 7.4 compatibility: fix deprecated curly brace array access

#1 @dd32
4 months ago

PemFTP

PHPClasses was the original source, and I don't know of any Canonical source for it anymore other than WordPress. I believe we've fixed other things in it since, so I would consider WordPress the most up to date source of that file.

POP3

The original sources of that class have long been abandoned and replaced in other projects with more modern alternatives, including in it's canonical location of SquirrelMail. WordPress is now the most recent variant of that class.

#2 @jorbin
4 months ago

In 45730:

PHP 7.4 compatibility fix / accessing arrays/string using curly brace syntax

PHP used to allow both square brackets and curly braces to be used interchangeably for accessing array elements and string offsets. The curly bracket syntax is only allowed in a limited set of cases and can be confusing for people not used to it.
PHP 7.4 will deprecate the curly brace syntax for accessing array elements and string offsets and it is expected that support will be completely removed in PHP 8.0.
Ref: https://wiki.php.net/rfc/deprecate_curly_braces_array_access

See #47751.
Props jrf.

#3 follow-up: @jorbin
4 months ago

  • Keywords php74 added

I included all of the patches other than getID3 as that is still an actively maintained project. Keeping this open as we should update that upstream library as they have already implemented this fix.

#4 in reply to: ↑ 3 @jrf
4 months ago

  • Keywords 2nd-opinion removed

Replying to jorbin:

I included all of the patches other than getID3 as that is still an actively maintained project. Keeping this open as we should update that upstream library as they have already implemented this fix.

Thanks for getting this in @jorbin <3

FYI: Both the 1.9 (master) branch as well as the 2.0 branch of GetID3 have been patched, though there is no new release yet containing the patches.

#5 follow-up: @desrosj
3 months ago

For updating getID3, there is #43836 for updating to the latest 1.9.x version. I think when that lands, changing the curly braces in the library to prevent these deprecation notices would be fine.

#6 in reply to: ↑ 5 @jrf
3 months ago

Replying to desrosj:

For updating getID3, there is #43836 for updating to the latest 1.9.x version. I think when that lands, changing the curly braces in the library to prevent these deprecation notices would be fine.

I think it would be better to ask the maintainer to tag a new release and then update to that version as there are numerous other bugfixes which haven't been included in a release yet.

I would also like to suggest considering upgrading to 2.0 if released in time. Upgrade path doesn't seem too difficult and would put us in a better position for moving towards autoloading/using Composer for the future.

#7 @jorbin
2 months ago

In 46112:

Update getID3 library to fix issues with PHP7.4

Updates to trunk version that includes fixes for PHP7.4

Changelog:
https://github.com/JamesHeinrich/getID3/compare/v1.9.14...00f3fbfd77e583099ca70a3cf0bc092e113d2b20

See: #47751,#47783.
Fixes: #48040.

#8 @jorbin
2 months ago

In 46113:

Comment out magic quote functions

Follow up to r46112.

See: #47751,#47783, #48040.

#9 @desrosj
2 months ago

#40883 was marked as a duplicate.

#10 @desrosj
2 months ago

getID3 officially tagged a new version containing the PHP7.4 changes. For consistency, 47751-remaining-getid3.diff includes the two changes made since [46112] to bring the library 100% in sync (with the exception of [46113]).

After 47751-remaining-getid3.diff is committed, I believe that everything here has been addressed.

Changes: https://github.com/JamesHeinrich/getID3/compare/00f3fbfd77e583099ca70a3cf0bc092e113d2b20...v1.9.18

For props, @jkitchen deserves props for initially patching up to version 1.9.14 (the current version at the time) over on #40883.

#11 @desrosj
2 months ago

#43836 was marked as a duplicate.

#12 @jorbin
2 months ago

  • Owner set to jorbin
  • Resolution set to fixed
  • Status changed from new to closed

In 46166:

External Library: Update getid3 to 1.9.18

Follow up to r46112 as getid3 has tagged an official release.

Changes: https://github.com/JamesHeinrich/getID3/compare/00f3fbfd77e583099ca70a3cf0bc092e113d2b20...v1.9.18

Props desrosj, jkitchen.
Fixes #47751 #40883 #43836.

#13 @jrf
2 months ago

🎉

Thanks @jorbin and @desrosj for getting this in!

Note: See TracTickets for help on using tickets.