#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: |
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...
- It is unclear when the next version will be released.
- WordPress currently includes version
1.9.14-201706111222
(June 2017), while the latest release is version1.9.17
, released February this year and version2.0
is already inalpha
.
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)
Change History (20)
@
5 years ago
[External Services_JSON] PHP 7.4 compatibility: fix deprecated curly brace array access
#1
@
5 years 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.
#3
follow-up:
↓ 4
@
5 years 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
@
5 years 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:
↓ 6
@
5 years 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
@
5 years 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.
#10
@
5 years 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.
#12
@
5 years ago
- Owner set to jorbin
- Resolution set to fixed
- Status changed from new to closed
In 46166:
[WP native files] PHP 7.4 compatibility: fix deprecated curly brace array access