Opened 7 years ago
Closed 7 years ago
#44124 closed defect (bug) (wontfix)
Adding is_countable() check to custom-header.php
Reported by: | ianbelanger | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | General | Keywords: | |
Focuses: | Cc: |
Description
Updating a single instance of count() in show_header_selector()
if ( count( $var ) > 0 ) { // Do something. }
with is_countable()
if ( is_countable( $var ) && count( $var ) > 0 ) { // Do something. }
in the custom-header.php file, in order to avoid warnings in PHP 7.2
Attachments (2)
Change History (11)
#4
@
7 years ago
You may also want to add a is_iterable()
wrapper around the foreach()
just below within the same function or move the whole block of code below within the if ( is_countable() & count() > 1 ) {}
wrapper.
https://core.trac.wordpress.org/browser/trunk/src/wp-admin/custom-header.php#L295
#5
@
7 years ago
@jrf I was going to work on the is_countable() instances first, but I think it does make sense to do them both in the same diff. I will update the diff and re-upload. Thanks for the input!
#6
@
7 years ago
- Milestone changed from Awaiting Review to 4.9.7
Related: #44123 - Utilize is_countable()
and is_iterable()
Polyfills
#7
@
7 years ago
- Keywords close added
- Version trunk deleted
Thanks for your patch @ianbelanger.
I don't believe this is appropriate use of is_countable()
. If a bug is introduced elsewhere which results in $headers
being set to a non-countable value (for example via the return value of get_uploaded_header_images()
), it's not a good idea to mask it via logic such as this. This is the reason that PHP now triggers warnings when attempting to count un-countable values since PHP 7.2.
See 44123#comment:11.
#9
@
7 years ago
- Keywords has-patch needs-testing close removed
- Milestone 4.9.8 deleted
- Resolution set to wontfix
- Status changed from new to closed
Looked this over. Agree that this instance of count()
should not be updated.
Breaking it down, $headers
could be of a type that is not countable, but only if the $_wp_default_headers
global is overridden. In this scenario, an error should be thrown to indicate improper usage of $_wp_default_headers
.
Updated custom-header.php with new is_countable() function