Re: should I be looking to eliminate all notices?

From: Date: Mon, 23 Apr 2007 19:56:21 +0000
Subject: Re: should I be looking to eliminate all notices?
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-253540@lists.php.net to get a copy of this message
Edward Vermillion wrote:
On Apr 21, 2007, at 6:35 PM, Justin Frim wrote:
I've always gone by the rule that if you're making software that other people will see or use, make it clean. Sometimes I'll "cheat" and stick a @ symbol in front of a line to shut up errors and warnings for that particular line, but usually I only do that for speed optimization. (ie. if it's in a short loop that cycles many times).
Your not saving any cycles. The error handler still gets called, the error just doesn't get shown. And '@' is just another way of ignoring an error in your program. Not really a good idea if you want to right good code. Ed
Surely that's faster than calling isset(), declaring another variable, and executing another if() statement though, no? Compare: <?php function myfunction($inputdata) { global $myarray; echo "foo"; return $myarray[$inputdata]; } function yourfunction($inputdata) { global $yourarray; echo "bar"; return $yourarray[subfunction($inputdata)]; } if ((@$funcresult=myfunction($_GET['formfield']))!==false) { //Do stuff with the data from $myarray[], after doing just a single if() comparison } if ((@$funcresult=yourfunction($_GET['formfield']))!==false) { //Do stuff with the data from $yourarray[], after doing just one more if() comparison } ?> vs: <?php function myfunction($inputdata) { global $myarray; echo "foo"; if ($inputdata!="") { return $myarray[$inputdata]; }else{ return false; } } function yourfunction($inputdata) { global $yourarray; echo "bar"; if ($inputdata!="") { return subfunction($yourarray[$inputdata]); }else{ return subfunction(false); } } if (isset($_GET['formfield'])) { $funcinput = $_GET['formfield']; }else{ $funcinput = ""; } $funcresult=myfunction($funcinput); if ($funcresult!==false) { //Now we can finally do stuff, after calling isset(), declaring a variable, and doing three if() comparisons } $funcresult=yourfunction($funcinput); if ($funcresult!==false) { //Finally do more stuff, after doing two more if() comparisons } ?> Now that's a stupid example, but, you get the idea.

« previous php.general (#253540) next »