Re: [PHP] should I be looking to eliminate all notices?
On Mon, April 23, 2007 2:56 pm, Justin Frim wrote: > Now that's a stupid example, but, you get the idea. Well, we agree that it's a stupid example... :-) :-) :-) http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] should I be looking to eliminate all notices?
On Mon, 2007-04-23 at 15:56 -0400, Justin Frim wrote: > 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? It's probably faster if no notice is generated. It's almost certainly slower if a notice *is* generated. It's definitely bad practice and a lazy way to hide poor implementation. Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] should I be looking to eliminate all notices?
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: //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: 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. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] should I be looking to eliminate all notices?
[snip] I don't really want to do a isset check for every index I have. [/snip] Premature optimization is the root of all evil. Checks like this will take nanoseconds to check. Find another way to optimize, like writing better SQL queries. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] should I be looking to eliminate all notices?
On Sat, April 21, 2007 6:35 pm, Justin Frim wrote: > 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). I don't think that's actually an optimization... PHP still does all the work to generate the error message, and then it just throws it away. @ is not "magic" enough to make PHP figure out what errors might happen and not record them -- It just "traps" the error before it gets to your eyes and discards it... So you're making the code slower to add @, not faster... -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] should I be looking to eliminate all notices?
On Sat, April 21, 2007 4:01 am, Ross wrote: > A quick one this morning. > > When coding should I be trying to code so there are no notices or is > it ok > to turn them off. > > I don't really want to do a isset check for every index I have. [dorothy voice] Do you want to write good code, or bad code? :-) [/dorothy] Leave E_NOTICE on and write better code. -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] should I be looking to eliminate all notices?
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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] should I be looking to eliminate all notices?
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). In any case, I don't think it's a good idea to rely on users disabling warnings and error messages from their PHP configuration file if you want the code to be portable. Personally, I leave all errors and warnings turned on, even for public PHP deployments. Ross wrote: A quick one this morning. When coding should I be trying to code so there are no notices or is it ok to turn them off. I don't really want to do a isset check for every index I have. Ross -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] should I be looking to eliminate all notices?
I really have to agree here. I have gone through a mature open source project over the last month or so, and removed EVERY notice. It honestly took all of about 2 hours to actually fix the notices. It really isn't hard to eliminate them, and if you are coding something the may be released, you don't know how the end-user will have their error_reporting. I think it's fairly "good practice" to eliminate them. - Original Message From: Edward Vermillion <[EMAIL PROTECTED]> To: Ross <[EMAIL PROTECTED]> Cc: php-general@lists.php.net Sent: Saturday, April 21, 2007 7:17:35 AM Subject: Re: [PHP] should I be looking to eliminate all notices? On Apr 21, 2007, at 4:01 AM, Ross wrote: > A quick one this morning. > > When coding should I be trying to code so there are no notices or > is it ok > to turn them off. > If you don't mind writing code that contains errors, notices are errors. Not serious, but it's not that hard to write code in php that doesn't produce errors. Unless > I don't really want to do a isset check for every index I have. your lazy about your code. Sorry if it sounds harsh, but if you don't want to even check this minor thing then you probably shouldn't be writing code that's going to see the light of day*. Read up on web security. Start here... http://phpsec.org/ I'm betting that if you don't care about checking for set indexes then you're not checking a lot of things that really need to be checked. Ed * Code to bee used on a box connected to the internet. If your just writing some script that you use on your local machine then what you do with notices is your business. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] should I be looking to eliminate all notices?
On Apr 21, 2007, at 4:01 AM, Ross wrote: A quick one this morning. When coding should I be trying to code so there are no notices or is it ok to turn them off. If you don't mind writing code that contains errors, notices are errors. Not serious, but it's not that hard to write code in php that doesn't produce errors. Unless I don't really want to do a isset check for every index I have. your lazy about your code. Sorry if it sounds harsh, but if you don't want to even check this minor thing then you probably shouldn't be writing code that's going to see the light of day*. Read up on web security. Start here... http://phpsec.org/ I'm betting that if you don't care about checking for set indexes then you're not checking a lot of things that really need to be checked. Ed * Code to bee used on a box connected to the internet. If your just writing some script that you use on your local machine then what you do with notices is your business. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] should I be looking to eliminate all notices?
2007. 04. 21, szombat keltezéssel 10.17-kor Ross ezt írta: > Should I care? Is it considered bad practice to just turn them off? some people consider it bad practice, yes I personally wouldn't say it is bad practice, but I am sure that in many cases notices can help finding bugs in your code. So I think it is a tool which can help in coding, you decide if you want to use it or not ;) greets Zoltán Németh > > > > ""Zoltn Nmeth"" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > When coding I think it is better to turn error_reporting to E_ALL and > > try to write code that emits no notices. > > > > Of course there might be some notices left, which you decide not to care > > about, in production notices should be turned off then > > > > greets > > Zoltn Nmeth > > > > 2007. 04. 21, szombat keltezssel 10.01-kor Ross ezt rta: > >> A quick one this morning. > >> > >> When coding should I be trying to code so there are no notices or is it > >> ok > >> to turn them off. > >> > >> I don't really want to do a isset check for every index I have. > >> > >> > >> Ross > >> > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] should I be looking to eliminate all notices?
> -Message d'origine- > De : Ross [mailto:[EMAIL PROTECTED] > Envoyé : samedi 21 avril 2007 11:18 > À : php-general@lists.php.net > Objet : Re: [PHP] should I be looking to eliminate all notices? > > Should I care? Is it considered bad practice to just turn them off? > > Yes you should, if you are using undeclared variables, this could lead to coding problems, and/or security problems depending on how you have acces to your php files setup. As a rule of thumb, i declare all variables and do check isset on my indexes, so far my framework/cms has over 4000 lines of codes and i adress each notice and warning accordingly... But then again, this is just my philosophy its really up to you to decide how you code, and how to adress issues that emmit notice messages.. If you don't adresse those message then be sure to turn error_reporting off on your production server. Besides, using isset is a good way of determining certain "states" of your programm flow, for me it comes in handy rather then being a long task.. I feel full control over what is happening in your script will lead you to 1. less errors, 2. a better understanding of your script wich then leads itself into 3. easier debugging (yup their are a lot of people who have scripts that "work" but don't really know why! ) Regards, Tim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] should I be looking to eliminate all notices?
Should I care? Is it considered bad practice to just turn them off? ""Zoltán Németh"" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > When coding I think it is better to turn error_reporting to E_ALL and > try to write code that emits no notices. > > Of course there might be some notices left, which you decide not to care > about, in production notices should be turned off then > > greets > Zoltán Németh > > 2007. 04. 21, szombat keltezéssel 10.01-kor Ross ezt írta: >> A quick one this morning. >> >> When coding should I be trying to code so there are no notices or is it >> ok >> to turn them off. >> >> I don't really want to do a isset check for every index I have. >> >> >> Ross >> > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] should I be looking to eliminate all notices?
When coding I think it is better to turn error_reporting to E_ALL and try to write code that emits no notices. Of course there might be some notices left, which you decide not to care about, in production notices should be turned off then greets Zoltán Németh 2007. 04. 21, szombat keltezéssel 10.01-kor Ross ezt írta: > A quick one this morning. > > When coding should I be trying to code so there are no notices or is it ok > to turn them off. > > I don't really want to do a isset check for every index I have. > > > Ross > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php