#57674 closed defect (bug) (fixed)
unregister_setting() raises a PHP warning on unknown settings
Reported by: | xknown | Owned by: | hellofromTonya |
---|---|---|---|
Milestone: | 6.4 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Options, Meta APIs | Keywords: | php81 has-patch has-unit-tests commit |
Focuses: | php-compatibility | Cc: |
Description
Starting from PHP 8.x, attempting to unregister an undefined setting results in PHP warnings: Warning: Trying to access array offset on value of type null
.
unregister_setting( 'somethingrandom', 'somethingrandom' );
Change History (14)
This ticket was mentioned in PR #4035 on WordPress/wordpress-develop by xknown.
22 months ago
#1
- Keywords has-patch has-unit-tests added
#2
@
16 months ago
- Focuses php-compatibility added
I'll mark this ticket as a php-compatibility
focus to include it in the PHP 8.1 compat exclusion list.
#3
@
16 months ago
- Milestone changed from Awaiting Review to 6.4
Good catch, we already check if $wp_registered_settings[ $option_name ]
is set there, so I think it makes sense to do the same for $new_allowed_options[ $option_group ]
.
This ticket was mentioned in Slack in #core-test by nicolefurlan. View the logs.
14 months ago
#6
@
14 months ago
I dropped this one in #core-test to hopefully get a test report so that we can include it in the 6.4 release.
#7
@
14 months ago
Test Report
This report validates that the indicated patch addresses the issue.
Patch tested: https://github.com/WordPress/wordpress-develop/pull/4035
Environment
- OS: macOS Ventura 13.4.1
- PHP: 8.2.11
- WordPress: trunk
Actual Results
- ✅ Issue resolved with patch.
- ✅ Unit tests pass.
Additional Notes
- I used WP CLI via
npm run env:cli
to test this and verified that when executingunregister_setting( 'somethingrandom', 'somethingrandom' );
on the CLI, theNotice: Trying to access array offset on value of type null in /var/www/src/wp-includes/option.php on line 2821
notice appears without the patch, and disappears after applying the patch. - I ran phpunit on
registration.php
vianpm run test:php --debug tests/phpunit/tests/option/registration.php
and verified that all unit tests pass inregistration.php
.
#8
@
14 months ago
Test Report
Patch Tested: https://github.com/WordPress/wordpress-develop/pull/4035
Environment:
WordPress - 6.4-beta2
OS - Windows
Browser - Chrome
Theme: Twenty Nineteen
PHP - 8.1.17
Active Plugin - None
Actual Results:
- ✅ After Applying Patch PHP warnings is Resolved. Patch is Working as Expected.
Screenshots :
Before Patch: https://prnt.sc/2fFQlHqLDN3X
After Patch : https://prnt.sc/hjkRvmewxIgl
#9
@
14 months ago
We have a couple of passing test reports here. Does this seem ready for commit
? (cc @hellofromTonya, @SergeyBiryukov)
#10
@
14 months ago
- Keywords needs-testing removed
- Owner set to hellofromTonya
- Status changed from new to reviewing
Thanks for the ping (and reminder) @nicolefurlan. The source code fix LGTM and is ready for commit. I'm not sure about the test, but am reviewing.
I'll set myself as owner for the review and commit.
#11
@
14 months ago
- Keywords commit added
The patch https://github.com/WordPress/wordpress-develop/pull/4035 is ready for commit. Will prep the commit in time for 6.4 Beta 3.
#12
@
14 months ago
The patch fixes 2 different PHP Warning|Notice scenarios:
- When the global
$new_allowed_options
isnull
, fixes raisingTrying to access array offset on value of type null
PHP Notice (PHP 7.4) | Warning (on PHP 8).
- When the global
$new_allowed_options
is anarray
and the setting group key does not exist, fixes raising "Undefined index: unknown_setting_group" PHP Notice (PHP 7) | Warning (on PHP 8).
See both scenarios in action https://3v4l.org/oeFUJ.
@hellofromTonya commented on PR #4035:
14 months ago
#14
Committed via https://core.trac.wordpress.org/changeset/56817.
Trac ticket: https://core.trac.wordpress.org/ticket/57674