#44167 closed defect (bug) (invalid)
Add is_countable() check to wp-admin/edit.php
| Reported by: | thrijith | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | General | Version: | |
| Severity: | normal | Keywords: | close |
| Cc: | Focuses: |
Description
Update code with is_countable() wherever necessary in wp-admin/edit-form-advanced.php
See #44123.
Attachments (1)
Change History (6)
#3
@
8 years ago
- Keywords close added
- Version trunk
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.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
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 ( is_array( $done ) ) { ... ... }If
$doneis 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):
$cars = array("Volvo","BMW","Toyota"); echo is_countable( $cars) ? count($cars) : 0;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:
$cars = ''; if( is_array( $cars ) ) { echo count($cars); }the above snippet will be enough because since
$carsis 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.