In PHP, if there is a conditional like this:
if ( is_numeric($my_var) && $my_var == 1 ) {
}
If the first part of the if is false, does the second part ($my_var == 1) get ever executed?
Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In your example the
$my_var == 1will not be executed (if it’s not numeric). PHP will determinate that the first part evaluated tofalseand so there is no benefit in executing the second part because you are using the&&AND operator.An example:
If the querystring variable
somethingis missing then it doesn’t check if it equals1. If it did then it could produce anUndefined indexnotice.You can also verify this behavior with something like:
Set
$test = '2'and thedie()will not stop execution. Set it to1and the die will execute and stop, thus you won’t seeExecution continues...Edit: there is some general information here (not PHP specific).