Opened 4 months ago
Closed 2 months ago
#63957 closed defect (bug) (fixed)
PHP 8.5: Using `null` as array offsets
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 6.9 | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | General | Keywords: | php85 has-patch needs-testing |
| Focuses: | php-compatibility | Cc: |
Description
Parent ticket for all things PHP 8.5: #63061
Using null as an array offset and when calling array_key_exists() is deprecated in PHP 8.5
There are some places in core that need to be fixed.
Two examples I've ran into today:
do_blocks calls parse_blocks on post content, which can parse a simple string as a block with blockName of null. So when functions like _wp_add_block_level_preset_styles (hooked to pre_render_block use $block['blockName'] and pass it to WP_Block_Type_Registry, this is where the warnings are triggered.
Another, more obvious on in WP_Theme_JSON: https://github.com/WordPress/wordpress-develop/blob/c5909c4c51044758e3e9d75551c70b9c7fbace5f/src/wp-includes/class-wp-theme-json.php#L2888-L2894 - $current_element can be null
Change History (17)
This ticket was mentioned in PR #9849 on WordPress/wordpress-develop by @swissspidy.
4 months ago
#1
- Keywords has-patch added; needs-patch removed
#2
@
4 months ago
- Keywords needs-testing added
Interesting, I haven't updated my local PHP version to 8.5 yet so I'm adding needs-testing for other testers to it give a try. Will post my result here as well this week.
#3
@
4 months ago
- Owner set to swissspidy
- Resolution set to fixed
- Status changed from new to closed
In 60809:
This ticket was mentioned in PR #10136 on WordPress/wordpress-develop by @mukesh27.
3 months ago
#4
Trac ticket: https://core.trac.wordpress.org/ticket/63957
@mukesh27 commented on PR #10136:
3 months ago
#5
Follow-up to #9849
@swissspidy commented on PR #10136:
3 months ago
#6
How did you encounter these? #9845 doesn't report them, which would indicate a lack of test coverage.
@mukesh27 commented on PR #10136:
3 months ago
#7
How did you encounter these? #9845 doesn't report them, which would indicate a lack of test coverage.
Yes.
@swissspidy commented on PR #10136:
3 months ago
#8
Yes there is a lack of test coverage?
In that case, some tests would be great :-)
#9
@
3 months ago
- Resolution fixed deleted
- Status changed from closed to reopened
Re-opening for PR https://github.com/WordPress/wordpress-develop/pull/10136
@swissspidy commented on PR #10136:
3 months ago
#10
Yes there is a lack of test coverage?
In that case, some tests would be great :-)
Curious to see any stack traces where these happen in action too, to find the root cause
#12
@
2 months ago
- Resolution fixed deleted
- Status changed from closed to reopened
It seems that 8.5 RC4 fixes a bug that prevented instances where a null offset is used from being flagged as deprecated. As a result, the test suite is currently failing for single site jobs using PHP 8.5.
This ticket was mentioned in Slack in #core by desrosj. View the logs.
2 months ago
This ticket was mentioned in PR #10498 on WordPress/wordpress-develop by @westonruter.
2 months ago
#14
This avoids a deprecation warning in PHP 8.5:
Using null as an array offset is deprecated, use an empty string instead /var/www/src/wp-includes/class-wp-date-query.php:516 /var/www/src/wp-includes/class-wp-date-query.php:170 /var/www/src/wp-includes/class-wp-query.php:2138 /var/www/src/wp-includes/class-wp-query.php:3958 /var/www/src/wp-includes/class-wp.php:704 /var/www/src/wp-includes/class-wp.php:824 /var/www/tests/phpunit/includes/abstract-testcase.php:1346 /var/www/tests/phpunit/includes/testcase-canonical.php:303 /var/www/tests/phpunit/tests/canonical.php:68 /var/www/vendor/bin/phpunit:122
Specifically, the issue is that $wpdb->blogs is null when not on a single-site install. So this ensures that the $wpdb->blogs column is only added to the $known_columns array when on multisite.
It also updates the $valid_columns array to only include multisite-related columns when on multisite, namely registered and last_updated.
[!NOTE]
Some multisite columns appear to not have been accounted for:wp_blog_versions.last_updated,wp_registration_log.date_registered, andwp_signups.activated.
Lastly, the phpdoc @var tags for $wpdb->blogs, $wpdb->blogmeta, and the other multisite-specific tables have been updated to indicate they may be null.
Trac ticket: https://core.trac.wordpress.org/ticket/63957
This issue was introduced in r37477 (https://github.com/WordPress/wordpress-develop/commit/381930974cdcf35b0db6539aaf91ea90d37c3787) for WordPress 4.6.0.
@westonruter commented on PR #10498:
2 months ago
#15
Added a few small nits. I don't think it's in the coding standards, but I prefer to have an empty line before a control structures.
Cool. I'll apply when committing.
@desrosj commented on PR #10498:
2 months ago
#16
I changed the PR description to point to Core-63957 since that's the more specific issue being addressed here.
Trac ticket: https://core.trac.wordpress.org/ticket/63957