WallabyKid;10976291 wrote:Is it really the conventional wisdom that every variable (index) should be checked against
isset or empty to be sure it has been defined before either using or ignoring it?
Of course not - just those that may or may not exist.
WallabyKid;10976291 wrote:Where...
$itemId = $_SESSION['itemId'];
becomes...
if(isset($_SESSION['itemId'])) $itemId = $_SESSION['itemId'];
I would much prefer something like:
$itemId = (isset($_SESSION['itemId']) ? (int)$_SESSION['itemId'] : NULL);
since that a) allows me to set a default value, b) allows me to do some basic sanitization/data casting, and c) does (a) and (b) while remaining compact.
WallabyKid;10976291 wrote: e.g. twice the code??? Really???
Yep. Really. If you don't like that, try skipping such checks in C/C++ code and watch the 'segmentation faults' take over your console. 🙂
WallabyKid;10976291 wrote:Or Consider...
<?php
if($var1) $var2='somevalue';
?>
<input type="text" value="<?php echo $var2; ?>" />
which becomes
<?php
if(isset($var1)) $var2='somevalue';
?>
<input type="text" value="<?php if(isset($var2)) echo $var2; ?>" />
Well now you're just being silly. Why call isset() two times? Just call it once and, if the external variable isn't defined, simply set a default value instead (eliminating the need for a 2nd, 3rd, ... nth call to isset()).
WallabyKid;10976291 wrote:In a large project this could really add up to what appears to me a substantial volume of otherwise superfluous code just to avoid Notice Level Errors?
Well then there's your problem. Your goal shouldn't be to avoid the error messages themselves, it should be to avoid the actual errors.
Otherwise, yes, this really could (and often does) add up to a lot of code. Welcome to the world of computer programming. 🙂
WallabyKid;10976291 wrote:Can the resulting Notice Errors add significantly to the server load for a given site?
You mean the actual error logging mechanism? I suppose there is technically some overhead (yet another justification for what you call "superfluous" code), but I doubt it's going to be anywhere near as significant as the primary bottleneck on your site (whatever that may be).