Re: there must be better way to handle "Null" undefined variables

From: Date: Mon, 08 Dec 2008 18:55:56 +0000
Subject: Re: there must be better way to handle "Null" undefined variables
References: 1  Groups: php.windows 
Request: Send a blank email to php-windows+get-29093@lists.php.net to get a copy of this message
--- On Mon, 12/8/08, James Crow <james@ultratans.com> wrote: > From: James Crow <james@ultratans.com> > Subject: Re: [PHP-WIN] there must be better way to handle "Null" undefined variables > To: fredsilsbee@yahoo.com > Cc: "Daniel Brown" <danbrown@php.net>, php-windows@lists.php.net > Date: Monday, December 8, 2008, 6:40 PM > On Mon, 2008-12-08 at 10:24 -0800, Fred Silsbee wrote: > > if you read my original post you'd see that I > already know this! > > > > I even inserted code to fix the problem. The problem > is that the > > > > values of the variable THE FIRST TIME are undefined as > shown by the code I > > > > inserted. > > > > I fixed the problem for one of the variables to make > sure I perceived the > > > > problem correctly not being a html guru! > > > > The question is again "Is there a better > way?" > > > > > > If I write code that may be on a server I do not or can not > control the > php.ini settings, I check for the existence of the variable > before I use > it. This does increase the code size somewhat, but it makes > the code > more reliable as well. If you are passing values through > HTTP Post or > Get you will need something like this anyway to keep from > typing the > super global variable name every time. > > if (get_magic_quotes_gpc()) > { > // this should not be needed, but > //some sites still use get_magic_quotes_gpc > if (array_key_exists('my_html_var', $_POST) > $my_html_var = > stripslashes($_POST['my_html_var']); > } > else > { > if (array_key_exists('my_html_var', $_POST) > $my_html_var = $_POST['my_html_var']; > } > if (!is_set($my_html_var)) > { > // set our variable to a known value > $my_html_var = 'somevalue'; > } > > Cheers, > James your general concept is correct...do it the right way I am not adhering to MY way but why isn't my fix OK? One variable fixed...fixing the rest would cause code gloat. I had a (flying) instrument instructor once who was famous for his teaching ability. If I made a mistake (and I did many times) he'd tell me why so I'd learn the concept. Thanks! BTW is there anything you consider abrasive in my posts? I am to the point to avoid post proliferation. Here is only the pertinent code! <form action="new_black_scholes.php" method="post"> <p> Black Scholes Option Price Calculator:<br /> temp website under Redhat Fedora 9 Linux:<br /> the first 5 boxes require input(try 100. 100. .12 .1 365.):<br /> </p> <p> StockPrice (required):<br /> <input type="text" size="20" maxlength="40" name="StockPrice" value="<?php if (IsSet($StockPrice)) { echo $StockPrice; } else { echo " "; } ?>" /> </p> <p> ExercisePrice (required):<br /> <input type="text" size="20" maxlength="40" name="ExercisePrice" value="<?php echo $ExercisePrice; ?>" /> </p>

« previous php.windows (#29093) next »