[wp-trac] [WordPress Trac] #44167: Add is_countable() check to wp-admin/edit.php
WordPress Trac
noreply at wordpress.org
Mon May 21 06:26:04 UTC 2018
#44167: Add is_countable() check to wp-admin/edit.php
-----------------------------------------+------------------------------
Reporter: thrijith | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: trunk
Severity: normal | Resolution:
Keywords: has-patch reporter-feedback | Focuses:
-----------------------------------------+------------------------------
Changes (by subrataemfluence):
* keywords: has-patch => has-patch reporter-feedback
Comment:
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 `$done` is not an array, the count will never be executed. So, to me
adding an extra check `is_countable()` inside `is_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:
{{{
$cars = ''
echo is_countable( $cars) ? count($cars) : 0;
}}}
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 `$cars` is not an array and
we are using `count()` inside `is_array( $cars ){ ... }` check already,
the code `count( $cars )` will never execute.
The bottom line is, to my understanding we do not need to have
`is_countable()` function when using `count()` inside `is_array()` check.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/44167#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list