#44167 closed defect (bug) (invalid)
Add is_countable() check to wp-admin/edit.php
Reported by: | thrijith | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | General | Keywords: | close |
Focuses: | Cc: |
Description
Update code with is_countable() wherever necessary in wp-admin/edit-form-advanced.php
See #44123.
Attachments (1)
Change History (6)
#3
@
6 years ago
- Keywords close added
- Version trunk deleted
Thanks for your patch @thrijith.
I agree with @subrataemfluence. I don't believe this is appropriate use of is_countable()
. If a bug is introduced elsewhere which results in $done
being set to a non-countable value (for example via the return value of bulk_edit_posts()
), 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.
Note: See
TracTickets for help on using
tickets.
Hi, thank you for the patch. However, although it is good to have is_countable() prior to actually count number of elements in an array, in this particular context I don't feel it is super necessary because before counting we are already checking
If
$done
is not an array, the count will never be executed. So, to me adding an extra checkis_countable()
insideis_array()
will cause extra burden.Here are some use cases (as I see it):
if we don't have the check
is_array()
,is_countable()
is an obvious choice.If we have this:
again, we must use
is_countable()
.But if we have this:
the above snippet will be enough because since
$cars
is not an array and we are usingcount()
insideis_array( $cars ){ ... }
check already, the codecount( $cars )
will never execute.The bottom line is, to my understanding we do not need to have
is_countable()
function when usingcount()
insideis_array()
check.