note 64077 deleted from function.exit by bjori
| From: | bjori@php.net | Date: | Fri, 07 Apr 2006 07:02:38 +0000 |
| Subject: | note 64077 deleted from function.exit by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-107489@lists.php.net to get a copy of this message | ||
Note Submitter: server at syserror dot co dot uk
Reason: in docs
----
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.