mercredi 11 avril 2018

PHP - Can I put the whole block of function that returns boolean inside the expression in if condition in PHP? Ex: if( function() { return true; })

I created a conditional statement in PHP lately. I've been bothered if I can put the whole block of a function inside the parenthesis or the expression in IF condition. For example:

if( ! function($some_vars) {
     //Execute logic of the function here
     return false;
}) {
     // Execute if the function above returns false;
}

PS: The code above does not return any error but does not execute the logic inside the function either. My question is: Are the code above possible and if this is possible, is it safe/recommended?

Thanks!

Aucun commentaire:

Enregistrer un commentaire