7
There are certain things still that do not enter my mind regarding PHP.
Because there is a function is_null
, when we can simply compare the values using a comparison operator. For example $variable === NULL
?
And why in some tutorials recommend the "inversion" of this check.
I mean, instead of using
if ($variable === NULL) {
// faça alguma coisa
}
Teach to use:
if (NULL === $variable) {
// faça alguma coisa
}
But in some frameworks, like Laravel, I see a lot:
if ( is_null($variable)) {
// faça alguma coisa
}
They say it’s quicker to do as in the second example.
But is that really something I should be worried about? Or is it just a ridiculous microtimization?
I must stop putting is_null
in my codes, since a comparison operator consumes less resource in memory than a function call?
Is there any standard (some FIG Standard) that helps in this task, to facilitate a standardization?
The second example calls if I am not mistaken check Yoda, serves for you to exchange the comparison for assignment in languages where it is used
=
for both of us.– rray
"Yoda conditions" for the intimate (I just saw on Wikiedia)
– Wallace Maxters