Agony Posted May 28, 2014 Share Posted May 28, 2014 $gallery_cache = new cache('gallery_content.php',$cachetime);if($gallery_cache->check_cache() !== false){}else{ $gallery_cache->start_cache();//stuff $gallery_cache->end_cache();} Thats the code for the part. As you can see the first if itself is empty {}. check_cache returns: return include($this->file) on or false. So im checking it for false to run another function or do nothing ( since if its not false it returns the include already). Link to comment Share on other sites More sharing options...
Ingolme Posted May 28, 2014 Share Posted May 28, 2014 There's no need for an empty code block. Just use the logically inverse statement: if($gallery_cache->check_cache() === false) { $gallery_cache->start_cache(); //stuff $gallery_cache->end_cache();} Link to comment Share on other sites More sharing options...
Agony Posted May 28, 2014 Author Share Posted May 28, 2014 indeed that's a better way. but calling a function inside if like that by itself isn't unusual practice? Link to comment Share on other sites More sharing options...
Ingolme Posted May 28, 2014 Share Posted May 28, 2014 There's no problem with doing it. If the function returns a value that is going to be evaluated then there's no problem. Link to comment Share on other sites More sharing options...
davej Posted May 29, 2014 Share Posted May 29, 2014 In some languages such as C you will often see both an assignment and a logical comparison together... while ((c = getc(fp)) != EOF) {//process character} ...however this can be somewhat confusing -- so it is often discouraged... Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now