unbelievably simple "if" failing in PHP
I have been banging my head against this one for a while now and have tried many versions of this code. I must be doing something very basic wrong ...
$pop = FALSE;
$pop = ($visits > 4);
if ($pop){
drupal_add_js(drupal_get_path('module', 'spester') .'/light.js');
}
var_dump($visits, $pop)
gives me
int(3) bool(false)
... and yet the expression inside my if evaluates.
Of course, if I instead do if{FASLE}{...}
, then my code behaves as e开发者_开发问答xpected ...
If that bool is false
, the if
body never gets executed. You can put a simple tracing echo
there and you'll see it.
It looks like some other executed code makes you think that the body is executed when in fact it isn't. Or you editing the wrong file. Or forgot to refresh it. Or something else...
Please don't blame PHP, you'll be 99.999% wrong.
Note: I hope FASLE is only a typo in your post. Also, check your warning/error display settings.
check the value of @visit variable and spit out the value of $pop. It could be that $visit has wrong value in it.
Also a better condition is
if ($pop == true)
{
//do this
}
精彩评论