note 34440 added to control-structures.else

From: Date: Sun, 27 Jul 2003 18:12:40 +0000
Subject: note 34440 added to control-structures.else
Groups: php.notes 
Request: Send a blank email to php-notes+get-52777@lists.php.net to get a copy of this message
Both examples below, however, are inefficent. In todays world it means everything to save execution time and be a stickler for this kind of thing. The reason I say this is because of the code which is repeated and does not need to be. Here is my corrected example: <?php if ( file_exists('./users/' . $HTTP_GET_VARS['user_small'] . '.jpg') ) { $HTTP_GET_VARS['user_small'] = 'notfound'; } ?> <img src="./users/<?php echo $HTTP_GET_VARS['user_small']; ?>" border="0" height="88" width="88"> This new example requires only 238 characters vs. the origional 311 or the "imrpoved" 315. Efficent code will save you much much time in the end. If the above example is multiplied 10 times, 75 bytes are wasted needlessly. 1000 times and you've lost 7.5kb. This may not seem like much, but consider that you have maybe 10 IF statements like this in each file- that 1000 just became 10,000 and it's now 75Kb. That can mean the difference between a page that loads during heavy usage periods and a page that makes the user wait. I recomend you always find the shortet, simpliest way to do your coding as it not only helps reduce clutter but also confusion. I've eliminated an entire second possible branch of code, so you know that if it doesn't return "notfound.jpg", the if statement has -nothing- to do with whatever problem you might have. Clutter is also eliminated as a 900 line file, although still large, is easier to manage than a 1000 line file. ---- Manual Page -- http://www.php.net/manual/en/control-structures.else.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34440 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34440&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34440&report=yes

« previous php.notes (#52777) next »