FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Eregi possible problem
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Eregi possible problem [message #169360 is a reply to message #169357] Wed, 08 September 2010 15:13 Go to previous messageGo to previous message
matt[1] is currently offline  matt[1]
Messages: 40
Registered: September 2010
Karma:
Member
On Sep 8, 8:12 am, GarryJones <mor...@algonet.se> wrote:
>>> What errors would not be a problem?
>
> Thanks for your answers, they really helped.
>
> Some errors, such as the one above just confuse users. If the code is
> still working its nothing they need to worry about. Seeing errors is
> okay for testing. If for instance you are on holiday on the day they
> right in the "depreciated" code you wont know about it. In the
> meantime hundreds of people might be clicking away from your website
> and not ordering your products.

Another reason to control error_reporting. You can simply turn this
off in production, or get advanced and override PHP error handling
methods to selectively display errors based on user permissions or
automatically email you when an error is encountered.

> Another common claimed "error" that is not an error: I use "post" to
> read in values from a form. According to what the user clicks on in
> the first form I show a different number of checkboxes in the second
> form. But to make things easier I still check for all checkbox values
> each time the code runs, its easier to run the entire code so I dont
> miss something. But useing post on a 'varname' from a checkbox that
> has not been displayed leads to the undefined index error message. Its
> not an error, I don't care that I am checking for something that is
> not there. But users who see error messages get worried.

That's PHP telling you that your code is sloppy. Unchecked checkboxes
don't get passed with POST/GET operations, so you are in effect doing
the same as the following:

$a = array(0, 1);
echo $a[2];

PHP is a loosely-typed language and lets you get away with things like
this. Stricter languages would consider this a fatal error.
Fortunately, PHP provides you with a host of functions to check your
variables before accessing them.

$checkbox1 = isset($_POST['checkbox1']) ? $_POST['checkbox1'] : null;

I recommend functionalizing the above:

function post($varname)
{
return isset($_POST[$varname]) ? $_POST[$varname] : null;
}

$checkbox1 = post("checkbox1");
$checkbox2 = post("checkbox2");
// etc.

>> Well, computers running from punch cards were doing their job just fine....
>
> :) Yep, thats me. I used to load and punch those, back in the good old
> days, started out in the 1970's on mainframes with paper tape and
> punch cards......... before the masses got involved.....

Then you've been around long enough to recognize the value of
explicitly checking data and doing research before performing upgrades
without doing an impact analysis on existing code...
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Another heredoc question
Next Topic: php filling in listbox value based on db record ??
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 23 01:48:22 GMT 2024

Total time taken to generate the page: 0.04481 seconds