3 ms·
I guess it can't hurt. But I wish WP's hooks fired less (read: once instead of multiple times), that would certainly help. It's also somewhat disheartening tha
by chiefalchemist 3y ago
I guess it can't hurt. But I wish WP's hooks fired less (read: once instead of multiple times), that would certainly help.
It's also somewhat disheartening that this:
Saving processing cycles by optimizing foreach - In WordPress Trac ticket #58457
made it into the code base in the first place, and stayed there for so long. Even if you're not focused on optimizing, the new & improved code simply makes better sense.
As a side note, my understanding is if elses are slightly more expensive than plain ifs.
Therefore:
if ( 1 === $x ) {
$y = 'foo';
} else {
$y = 'bar';
}
is slightly better as:
$y = 'bar';
if ( 1 === $x ) {
$y = 'foo';
}
There's no need for an else. Minor? Perhaps. But if nothing else it shows you're thinking, are intentional, etc.