note 64077 added to function.exit

From: Date: Fri, 07 Apr 2006 00:35:34 +0000
Subject: note 64077 added to function.exit
Groups: php.notes 
Request: Send a blank email to php-notes+get-107476@lists.php.net to get a copy of this message
Redundant coding bad, return good! badtest.inc.php: <?php echo "Main Text!"; if(foo == bar) { _do_something(); } else { echo "Footer Text!"; die(); } echo "Some more main text, that we want to skip if foo != bar"; ?> goodtest.inc.php: <?php echo "Main Text!"; if(foo == bar) { _do_something(); } else { return; } echo "Some more main text, that we want to skip if foo != bar"; ?> short_goodtest.inc.php: <?php echo "Main Text!"; if(foo == bar) _do_something(); else return; echo "Some more main text, that we want to skip if foo != bar"; ?> index.php: <?php echo "Header Text!"; require("???test.inc.php"); echo "Footer Text!"; ?> Notice on badtest.php you have to repeat the "Footer Text!" again before the die(); Now imagine you have 10 includes instead of ust "Footer Text!", do you want to write: <?php require(SOMETHING_DIR . SOME_FILE); require(ANOTHER_DIR . OTHER_FILE); require(ONE_MORE_DIR . FILE); // ... etc ... *then* Die(); // instead of *just* return; ?> every time you want to stop processing an include/require part way through? Apart from being very slow coding (having to copy/paste), being a pain to update (say you want to remove ANOTHER_DIR.OTHER_FILE, you then have to find every Die(); and remove the require above it), your file sizes will be massive! PS: Can anyone confirm if this affects preformance either positivly or negitivly? I would assume there is no difference. ---- Server IP: 85.116.0.130 Probable Submitter: 212.158.244.38 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.exit.php Edit -- http://master.php.net/note/edit/64077 Del: integrated -- http://master.php.net/note/delete/64077/integrated Del: useless -- http://master.php.net/note/delete/64077/useless Del: bad code -- http://master.php.net/note/delete/64077/bad+code Del: spam -- http://master.php.net/note/delete/64077/spam Del: non-english -- http://master.php.net/note/delete/64077/non-english Del: in docs -- http://master.php.net/note/delete/64077/in+docs Del: other reasons-- http://master.php.net/note/delete/64077 Reject -- http://master.php.net/note/reject/64077 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#107476) next »