Jump to content

running function in if statement - good or bad practice?


Agony

Recommended Posts

$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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...