Re: [PHP] isset empty or ...?
http://www.php.net/manual/en/types.comparisons.php Maybe first table PHP functions comparison (including 'isset' and 'empty') could help you. 31.03.2013 в 8:53, John Taylor-Johnston написал(а): I'm using if($mydata-DPRresponselocationaddress1 != ) is this the same as if (!isset($mydata-DPRresponselocationaddress)) http://php.net/manual/en/function.isset.php or if (!empty($mydata-DPRresponselocationaddress)) http://php.net/manual/en/function.empty.php or is there another function I have not learned yet? I don't really get the difference between isset and empty. John -- С уважением, Александр Меньщиков Тел.: +7 921 408-6-777 E-mail: amenshchi...@gmail.com pgpx34Zv0GMRg.pgp Description: PGP signature
[PHP] isset empty or ...?
I'm using if($mydata-DPRresponselocationaddress1 != ) is this the same as if (!isset($mydata-DPRresponselocationaddress)) http://php.net/manual/en/function.isset.php or if (!empty($mydata-DPRresponselocationaddress)) http://php.net/manual/en/function.empty.php or is there another function I have not learned yet? I don't really get the difference between isset and empty. John -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] isset not functioning
I created a simple survey for my work website, most of the PHP is on my process.php document, which is referenced by a form on a seperate page containing the form with the method of post. On my process.php page, the script obtains the field data using the $_REQUEST[] function. I have a small if statement to check to see if they filled out the 'firstname' field, and if they did not, to replace $name with Sir or Madam. Unfortunately, $name always equals Sir or Madam, wether a value for firstname was entered or not. All the of the other instances of using $_REQUEST[] functions just fine, but don't make use of if or isset. Here is the code snippet: if(isset($_REQUEST['firstname']) !empty($RESULT['firstname'])) { $name = $_REQUEST['firstname']; } else { $name = 'Sir or Madam'; } I also tried adding an underscore to $RESULT (I got the code for this from a php.net comment on the manual), to make it $_RESULT, but this doesn't seem to be a pre-set function, and it still does not make it work. I am guessing the user neglected to define $RESULT in his snippet, or I overlooked it. Can anyone see any problems with the code?
Re: [PHP] isset not functioning
On Mon, Aug 3, 2009 at 1:08 PM, Allen McCabeallenmcc...@gmail.com wrote: I created a simple survey for my work website, most of the PHP is on my process.php document, which is referenced by a form on a seperate page containing the form with the method of post. On my process.php page, the script obtains the field data using the $_REQUEST[] function. I have a small if statement to check to see if they filled out the 'firstname' field, and if they did not, to replace $name with Sir or Madam. Unfortunately, $name always equals Sir or Madam, wether a value for firstname was entered or not. All the of the other instances of using $_REQUEST[] functions just fine, but don't make use of if or isset. Here is the code snippet: if(isset($_REQUEST['firstname']) !empty($RESULT['firstname'])) { $name = $_REQUEST['firstname']; } else { $name = 'Sir or Madam'; } I also tried adding an underscore to $RESULT (I got the code for this from a php.net comment on the manual), to make it $_RESULT, but this doesn't seem to be a pre-set function, and it still does not make it work. I am guessing the user neglected to define $RESULT in his snippet, or I overlooked it. Can anyone see any problems with the code? You are switching from $_REQUEST to $RESULT. Trying to use $_RESULT won't make it any better. Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset not functioning
Your if-statement should be like this: [code] if(isset($_REQUEST['firstname']) !empty($_REQUEST['firstname'])) { ... } [/code] -- --- Contact info: Skype: parham-d MSN: fire_lizard16 at hotmail dot com email: parham90 at GMail dot com Allen McCabe allenmcc...@gmail.com wrote in message news:657acef20908031008nc2c29cdo3e13733bc6f29...@mail.gmail.com... I created a simple survey for my work website, most of the PHP is on my process.php document, which is referenced by a form on a seperate page containing the form with the method of post. On my process.php page, the script obtains the field data using the $_REQUEST[] function. I have a small if statement to check to see if they filled out the 'firstname' field, and if they did not, to replace $name with Sir or Madam. Unfortunately, $name always equals Sir or Madam, wether a value for firstname was entered or not. All the of the other instances of using $_REQUEST[] functions just fine, but don't make use of if or isset. Here is the code snippet: if(isset($_REQUEST['firstname']) !empty($RESULT['firstname'])) { $name = $_REQUEST['firstname']; } else { $name = 'Sir or Madam'; } I also tried adding an underscore to $RESULT (I got the code for this from a php.net comment on the manual), to make it $_RESULT, but this doesn't seem to be a pre-set function, and it still does not make it work. I am guessing the user neglected to define $RESULT in his snippet, or I overlooked it. Can anyone see any problems with the code? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset not functioning
On Mon, 03 Aug 2009 20:11:44 +0300, Parham Doustdar parha...@gmail.com wrote: Your if-statement should be like this: [code] if(isset($_REQUEST['firstname']) !empty($_REQUEST['firstname'])) { ... } [/code] Or even: [code] if(!empty($_REQUEST['firstname'])) { ... } [/code] Because empty will also check if variable exists -- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset not functioning -RESOLVED
Thanks! On Mon, Aug 3, 2009 at 10:13 AM, Andrew Ballard aball...@gmail.com wrote: On Mon, Aug 3, 2009 at 1:08 PM, Allen McCabeallenmcc...@gmail.com wrote: I created a simple survey for my work website, most of the PHP is on my process.php document, which is referenced by a form on a seperate page containing the form with the method of post. On my process.php page, the script obtains the field data using the $_REQUEST[] function. I have a small if statement to check to see if they filled out the 'firstname' field, and if they did not, to replace $name with Sir or Madam. Unfortunately, $name always equals Sir or Madam, wether a value for firstname was entered or not. All the of the other instances of using $_REQUEST[] functions just fine, but don't make use of if or isset. Here is the code snippet: if(isset($_REQUEST['firstname']) !empty($RESULT['firstname'])) { $name = $_REQUEST['firstname']; } else { $name = 'Sir or Madam'; } I also tried adding an underscore to $RESULT (I got the code for this from a php.net comment on the manual), to make it $_RESULT, but this doesn't seem to be a pre-set function, and it still does not make it work. I am guessing the user neglected to define $RESULT in his snippet, or I overlooked it. Can anyone see any problems with the code? You are switching from $_REQUEST to $RESULT. Trying to use $_RESULT won't make it any better. Andrew
Re: [PHP] isset not functioning
if(isset($_REQUEST['firstname']) !empty($RESULT['firstname'])) { $name = $_REQUEST['firstname']; } else { $name = 'Sir or Madam'; } Can anyone see any problems with the code? Your conditional will never evaluate to true. What is $RESULT? Where did it come from? $RESULT is not a built-in PHP variable or function, so empty($RESULT) will always be true, making !empty(...) always false. Also, it should be noted that if a form field exists, it will exist in the form data POSTed to PHP, even if the field is empty. I'm guessing that what you want to do is something like this: if(!empty($_POST['firstname']) { $name = $_POST['firstname']; } else { $name = 'Sir or Madam'; } empty() will evaluate to false if the field is empty OR if the field does not exist. Also not the use of $_POST instead of $_REQUEST. This will ensure that your data is actually coming from the form instead of an attacker trying to inject data with $_GET variables or some other source. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] isset not functioning
Io, try do like this: You should use $_POST for the security, using $_REQUEST some users can pass a inject or someting to crash the aplication, and addslashes is for more security $firstName = addslashes($_POST['firstname']); if(isset($firstName) !empty($firstName)) { $name = $firstName; } else { $name = 'Sir or Madam'; } Yuri Yarlei. Programmer PHP, CSS, Java, PostregreSQL; Today PHP, tomorrow Java, after the world. Kyou wa PHP, ashita wa Java, sono ato sekai desu. Date: Mon, 3 Aug 2009 10:08:08 -0700 From: allenmcc...@gmail.com To: parha...@gmail.com CC: php-general@lists.php.net Subject: [PHP] isset not functioning I created a simple survey for my work website, most of the PHP is on my process.php document, which is referenced by a form on a seperate page containing the form with the method of post. On my process.php page, the script obtains the field data using the $_REQUEST[] function. I have a small if statement to check to see if they filled out the 'firstname' field, and if they did not, to replace $name with Sir or Madam. Unfortunately, $name always equals Sir or Madam, wether a value for firstname was entered or not. All the of the other instances of using $_REQUEST[] functions just fine, but don't make use of if or isset. Here is the code snippet: if(isset($_REQUEST['firstname']) !empty($RESULT['firstname'])) { $name = $_REQUEST['firstname']; } else { $name = 'Sir or Madam'; } I also tried adding an underscore to $RESULT (I got the code for this from a php.net comment on the manual), to make it $_RESULT, but this doesn't seem to be a pre-set function, and it still does not make it work. I am guessing the user neglected to define $RESULT in his snippet, or I overlooked it. Can anyone see any problems with the code? _ Novo Internet Explorer 8. Baixe agora, é grátis! http://brasil.microsoft.com.br/IE8/mergulhe/?utm_source=MSN%3BHotmailutm_medium=Taglineutm_campaign=IE8
RE: [PHP] isset question
On 19 June 2009 19:53, Ashley Sheridan advised: On Fri, 2009-06-19 at 12:36 +0100, Ford, Mike wrote: On 18 June 2009 20:25, LAMP advised: using !empty() instead isset() will work if you don't care for PHP Notice: Undefined variable... If you want to avoid PHP Notice you have to use both: $msg.= (isset($_POST['mort']) and !empty($_POST['mort'])) ? The mortgage amount is $mort\n : ; Absolute rubbish -- as it says at http://php.net/empty, empty($var) is the opposite of (boolean)$var, except that no warning is generated when the variable is not set. -- so protecting empty() with an isset() is a total waste of time, space and cpu cycles. Cheers! Mike -- Mike Ford, Electronic Information Developer, C507, Leeds Metropolitan University, Civic Quarter Campus, Woodhouse Lane, LEEDS, LS1 3HE, United Kingdom Email: m.f...@leedsmet.ac.uk Tel: +44 113 812 4730 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm To be honest, you're still opening yourself up to attack that way. What I'd do is first assign the variable to a forced int, and then use that result if it is 0: $mortgage = (isset($_REQUEST['mort'])?intval($_REQUEST['mort']):0; $msg .= ($mortgage 0)?The mortgage amount is $mortgage:; Too true -- I have a parameter-checking system that does this automatically for me, so I tend not to think of it when writing actual processing code. My bad, probably, but good catch. Cheers! Mike -- Mike Ford, Electronic Information Developer, C507, Leeds Metropolitan University, Civic Quarter Campus, Woodhouse Lane, LEEDS, LS1 3HE, United Kingdom Email: m.f...@leedsmet.ac.uk Tel: +44 113 812 4730 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset question
How does echoing back to the page make it vulnerable? This does not go to a DB if that makes any difference. Gary Paul M Foster pa...@quillandmouse.com wrote in message news:20090621032151.gb14...@quillandmouse.com... On Sat, Jun 20, 2009 at 12:20:56PM +0100, Ashley Sheridan wrote: On Sat, 2009-06-20 at 00:19 -0400, Paul M Foster wrote: On Fri, Jun 19, 2009 at 07:52:40PM +0100, Ashley Sheridan wrote: On Fri, 2009-06-19 at 12:36 +0100, Ford, Mike wrote: On 18 June 2009 20:25, LAMP advised: using !empty() instead isset() will work if you don't care for PHP Notice: Undefined variable... If you want to avoid PHP Notice you have to use both: $msg.= (isset($_POST['mort']) and !empty($_POST['mort'])) ? The mortgage amount is $mort\n : ; Absolute rubbish -- as it says at http://php.net/empty, empty($var) is the opposite of (boolean)$var, except that no warning is generated when the variable is not set. -- so protecting empty() with an isset() is a total waste of time, space and cpu cycles. snip To be honest, you're still opening yourself up to attack that way. Why and how? Paul -- Paul M. Foster I've only done a little reading on this, but you're opening yourself up to a XSS attack. If someone posted 'script//malicious code here/script' to your PHP script, you'd essentially be printing that right back out onto your page. I see. You're not talking about being vulnerable because of isset/empty, but by echoing it back to the page. Yes, I agree there. You have to sanitize it first. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset question
On Sun, 2009-06-21 at 13:57 -0400, Gary wrote: How does echoing back to the page make it vulnerable? This does not go to a DB if that makes any difference. Gary Paul M Foster pa...@quillandmouse.com wrote in message news:20090621032151.gb14...@quillandmouse.com... On Sat, Jun 20, 2009 at 12:20:56PM +0100, Ashley Sheridan wrote: On Sat, 2009-06-20 at 00:19 -0400, Paul M Foster wrote: On Fri, Jun 19, 2009 at 07:52:40PM +0100, Ashley Sheridan wrote: On Fri, 2009-06-19 at 12:36 +0100, Ford, Mike wrote: On 18 June 2009 20:25, LAMP advised: using !empty() instead isset() will work if you don't care for PHP Notice: Undefined variable... If you want to avoid PHP Notice you have to use both: $msg.= (isset($_POST['mort']) and !empty($_POST['mort'])) ? The mortgage amount is $mort\n : ; Absolute rubbish -- as it says at http://php.net/empty, empty($var) is the opposite of (boolean)$var, except that no warning is generated when the variable is not set. -- so protecting empty() with an isset() is a total waste of time, space and cpu cycles. snip To be honest, you're still opening yourself up to attack that way. Why and how? Paul -- Paul M. Foster I've only done a little reading on this, but you're opening yourself up to a XSS attack. If someone posted 'script//malicious code here/script' to your PHP script, you'd essentially be printing that right back out onto your page. I see. You're not talking about being vulnerable because of isset/empty, but by echoing it back to the page. Yes, I agree there. You have to sanitize it first. Paul -- Paul M. Foster My assumption was that because it was displaying the mortgage amount to the user, that it would at some point store it too. Thanks Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset question
On Sat, 2009-06-20 at 00:19 -0400, Paul M Foster wrote: On Fri, Jun 19, 2009 at 07:52:40PM +0100, Ashley Sheridan wrote: On Fri, 2009-06-19 at 12:36 +0100, Ford, Mike wrote: On 18 June 2009 20:25, LAMP advised: using !empty() instead isset() will work if you don't care for PHP Notice: Undefined variable... If you want to avoid PHP Notice you have to use both: $msg.= (isset($_POST['mort']) and !empty($_POST['mort'])) ? The mortgage amount is $mort\n : ; Absolute rubbish -- as it says at http://php.net/empty, empty($var) is the opposite of (boolean)$var, except that no warning is generated when the variable is not set. -- so protecting empty() with an isset() is a total waste of time, space and cpu cycles. snip To be honest, you're still opening yourself up to attack that way. Why and how? Paul -- Paul M. Foster I've only done a little reading on this, but you're opening yourself up to a XSS attack. If someone posted 'script//malicious code here/script' to your PHP script, you'd essentially be printing that right back out onto your page. Thanks Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset question
Waynn Lue wrote: I notice that you're checking $_POST['mort'] but you're echoing $mort, is that your actual code? That was my observation as well. Is $mort = $POST['mort']; being set somewhere else or not? If not, how is your script supposed to know what value $mort should be? And, what the other guys said. Gary, before you do anything with submitted data you need to process it against strip_tags() and/or htmlentities() at the very least, mysql_real_escape_string() if the data goes to a db. Reese -- On 6/18/09, Gary gwp...@ptd.net wrote: I have a form that gives the submitter a choice or either one set of questions, or another. I am still getting the message even if the input was left blank. So on the line below, $msg.= isset($_POST['mort']) ? The mortgage amount is $mort\n : ; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset question
Yes... I echo the code onto the page as well as sending out the message. The echo is sort of a thank you page, this is what you submitted. A message, which is not going into a DB, is also emailed to the submitter and cleint. Gary Waynn Lue waynn...@gmail.com wrote in message news:d29bea5e0906181231r165c5844wecd7d34026621...@mail.gmail.com... I notice that you're checking $_POST['mort'] but you're echoing $mort, is that your actual code? On 6/18/09, Gary gwp...@ptd.net wrote: I have a form that gives the submitter a choice or either one set of questions, or another. I am still getting the message even if the input was left blank. So on the line below, $msg.= isset($_POST['mort']) ? The mortgage amount is $mort\n : ; I get The mortgage amount is What am I missing here? Thanks Gary -- 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] isset question
On Sat, Jun 20, 2009 at 12:20:56PM +0100, Ashley Sheridan wrote: On Sat, 2009-06-20 at 00:19 -0400, Paul M Foster wrote: On Fri, Jun 19, 2009 at 07:52:40PM +0100, Ashley Sheridan wrote: On Fri, 2009-06-19 at 12:36 +0100, Ford, Mike wrote: On 18 June 2009 20:25, LAMP advised: using !empty() instead isset() will work if you don't care for PHP Notice: Undefined variable... If you want to avoid PHP Notice you have to use both: $msg.= (isset($_POST['mort']) and !empty($_POST['mort'])) ? The mortgage amount is $mort\n : ; Absolute rubbish -- as it says at http://php.net/empty, empty($var) is the opposite of (boolean)$var, except that no warning is generated when the variable is not set. -- so protecting empty() with an isset() is a total waste of time, space and cpu cycles. snip To be honest, you're still opening yourself up to attack that way. Why and how? Paul -- Paul M. Foster I've only done a little reading on this, but you're opening yourself up to a XSS attack. If someone posted 'script//malicious code here/script' to your PHP script, you'd essentially be printing that right back out onto your page. I see. You're not talking about being vulnerable because of isset/empty, but by echoing it back to the page. Yes, I agree there. You have to sanitize it first. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] isset question
On 18 June 2009 20:25, LAMP advised: using !empty() instead isset() will work if you don't care for PHP Notice: Undefined variable... If you want to avoid PHP Notice you have to use both: $msg.= (isset($_POST['mort']) and !empty($_POST['mort'])) ? The mortgage amount is $mort\n : ; Absolute rubbish -- as it says at http://php.net/empty, empty($var) is the opposite of (boolean)$var, except that no warning is generated when the variable is not set. -- so protecting empty() with an isset() is a total waste of time, space and cpu cycles. Cheers! Mike -- Mike Ford, Electronic Information Developer, C507, Leeds Metropolitan University, Civic Quarter Campus, Woodhouse Lane, LEEDS, LS1 3HE, United Kingdom Email: m.f...@leedsmet.ac.uk Tel: +44 113 812 4730 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] isset question
On Fri, 2009-06-19 at 12:36 +0100, Ford, Mike wrote: On 18 June 2009 20:25, LAMP advised: using !empty() instead isset() will work if you don't care for PHP Notice: Undefined variable... If you want to avoid PHP Notice you have to use both: $msg.= (isset($_POST['mort']) and !empty($_POST['mort'])) ? The mortgage amount is $mort\n : ; Absolute rubbish -- as it says at http://php.net/empty, empty($var) is the opposite of (boolean)$var, except that no warning is generated when the variable is not set. -- so protecting empty() with an isset() is a total waste of time, space and cpu cycles. Cheers! Mike -- Mike Ford, Electronic Information Developer, C507, Leeds Metropolitan University, Civic Quarter Campus, Woodhouse Lane, LEEDS, LS1 3HE, United Kingdom Email: m.f...@leedsmet.ac.uk Tel: +44 113 812 4730 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm To be honest, you're still opening yourself up to attack that way. What I'd do is first assign the variable to a forced int, and then use that result if it is 0: $mortgage = (isset($_REQUEST['mort'])?intval($_REQUEST['mort']):0; $msg .= ($mortgage 0)?The mortgage amount is $mortgage:; Thanks Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset question
On Fri, Jun 19, 2009 at 07:52:40PM +0100, Ashley Sheridan wrote: On Fri, 2009-06-19 at 12:36 +0100, Ford, Mike wrote: On 18 June 2009 20:25, LAMP advised: using !empty() instead isset() will work if you don't care for PHP Notice: Undefined variable... If you want to avoid PHP Notice you have to use both: $msg.= (isset($_POST['mort']) and !empty($_POST['mort'])) ? The mortgage amount is $mort\n : ; Absolute rubbish -- as it says at http://php.net/empty, empty($var) is the opposite of (boolean)$var, except that no warning is generated when the variable is not set. -- so protecting empty() with an isset() is a total waste of time, space and cpu cycles. snip To be honest, you're still opening yourself up to attack that way. Why and how? Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] isset question
I have a form that gives the submitter a choice or either one set of questions, or another. I am still getting the message even if the input was left blank. So on the line below, $msg.= isset($_POST['mort']) ? The mortgage amount is $mort\n : ; I get The mortgage amount is What am I missing here? Thanks Gary -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset question
2009/6/18 Gary gwp...@ptd.net: I have a form that gives the submitter a choice or either one set of questions, or another. I am still getting the message even if the input was left blank. So on the line below, $msg.= isset($_POST['mort']) ? The mortgage amount is $mort\n : ; I get The mortgage amount is What am I missing here? A variable isset even if it's empty. Either compare it to an empty string or test the result from strlen against 0. -Stuart -- http://stut.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset question
Use !empty($_POST['mort']) instead of isset() for form input since the form will still set an empty value if left blank. Gary wrote: I have a form that gives the submitter a choice or either one set of questions, or another. I am still getting the message even if the input was left blank. So on the line below, $msg.= isset($_POST['mort']) ? The mortgage amount is $mort\n : ; I get The mortgage amount is What am I missing here? Thanks Gary No virus found in this incoming message. Checked by AVG - www.avg.com Version: 8.5.339 / Virus Database: 270.12.78/2185 - Release Date: 06/18/09 05:53:00 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset question
Steve wrote: Use !empty($_POST['mort']) instead of isset() for form input since the form will still set an empty value if left blank. Gary wrote: I have a form that gives the submitter a choice or either one set of questions, or another. I am still getting the message even if the input was left blank. So on the line below, $msg.= isset($_POST['mort']) ? The mortgage amount is $mort\n : ; I get The mortgage amount is What am I missing here? Thanks Gary No virus found in this incoming message. Checked by AVG - www.avg.com Version: 8.5.339 / Virus Database: 270.12.78/2185 - Release Date: 06/18/09 05:53:00 using !empty() instead isset() will work if you don't care for PHP Notice: Undefined variable... If you want to avoid PHP Notice you have to use both: $msg.= (isset($_POST['mort']) and !empty($_POST['mort'])) ? The mortgage amount is $mort\n : ; afan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset question
I notice that you're checking $_POST['mort'] but you're echoing $mort, is that your actual code? On 6/18/09, Gary gwp...@ptd.net wrote: I have a form that gives the submitter a choice or either one set of questions, or another. I am still getting the message even if the input was left blank. So on the line below, $msg.= isset($_POST['mort']) ? The mortgage amount is $mort\n : ; I get The mortgage amount is What am I missing here? Thanks Gary -- 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] isset question
The isset or empty, it's return a boolean (true 1, false 0), the isset will return true if the variable will have been initiated, the empty will return true if the variable is empty, but for that the variable need to be initiated. You can do it in a many ways, like: $msg.= (isset($_POST['mort']) !empty($_POST['mort']) ? The mortgage amount is $mort\n : ); or $msg.= ($_POST['mort'] == '' ? The mortgage amount is $mort\n : ); or $msg.= (strlen($_POST['mort']) 0 ? The mortgage amount is $mort\n : ); Yuri Yarlei. Programmer PHP, CSS, Java, PostregreSQL; Today PHP, tomorrow Java, after the world. Kyou wa PHP, ashita wa Java, sono ato sekai desu. Date: Thu, 18 Jun 2009 20:07:09 +0100 From: stut...@gmail.com To: gwp...@ptd.net CC: php-general@lists.php.net Subject: Re: [PHP] isset question 2009/6/18 Gary gwp...@ptd.net: I have a form that gives the submitter a choice or either one set of questions, or another. I am still getting the message even if the input was left blank. So on the line below, $msg.= isset($_POST['mort']) ? The mortgage amount is $mort\n : ; I get The mortgage amount is What am I missing here? A variable isset even if it's empty. Either compare it to an empty string or test the result from strlen against 0. -Stuart -- http://stut.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php _ Conheça os novos produtos Windows Live! Clique aqui. http://www.windowslive.com.br
[PHP] isset($a-b) even if $a-b = null
how do i test if a property of a stdclass object is set, even if its value is null, similar to how array_key_exists() works for arrays. the following method fails: $a-b = null; if(isset($a-b)) echo yes; and property_exists() seems only to work for defined objects. hope someone can help. thanks! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset($a-b) even if $a-b = null
Olav Mørkrid schreef: how do i test if a property of a stdclass object is set, even if its value is null, similar to how array_key_exists() works for arrays. the following method fails: $a-b = null; if(isset($a-b)) echo yes; and property_exists() seems only to work for defined objects. hope someone can help. thanks! if (isset($a - b) $a - b != null) { echo yes; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset($a-b) even if $a-b = null
On 8/17/07, Olav Mørkrid [EMAIL PROTECTED] wrote: how do i test if a property of a stdclass object is set, even if its value is null, similar to how array_key_exists() works for arrays. the following method fails: $a-b = null; if(isset($a-b)) echo yes; and property_exists() seems only to work for defined objects. hope someone can help. thanks! Seems your asking for something similar to perl's exists() function.. Best I can come up with is... $a-b = null; if (is_null($a-b) || isset($a-b)) { print yes; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Isset Errors
Anyone got any suggestions on getting rid of these errors below? [Wed May 09 08:59:05 2007] [error] [client 192.168.225.246] PHP Notice: Undefined index: userstate in /srv/www/htdocs/resetpw.php on line 31, referer: https://ams.unt.edu/resetpw.php [Wed May 09 08:59:05 2007] [error] [client 192.168.225.246] PHP Notice: Undefined index: userstate in /srv/www/htdocs/resetpw.php on line 36, referer: https://ams.unt.edu/resetpw.php Here's the lines of code I am getting the errors in PHP 5...Where can I insert some code to define 'userstate' ? 24. if (identifyUser()) { 25. if ((isset($_SESSION['clientinfo']['ssn'][0]) strcmp('9', $_SESSION['clientinfo']['ssn'][0])) 26. || isset($_SESSION['clientsinfo'])) { 27. $_SESSION['userstate'] = 'confirmssn'; 28. } else { 29. $_SESSION['userstate'] = 'ssnverified'; 30. } 31. } elseif ($_SESSION['userstate'] == 'confirmssn' confirmSSN()) { 32. $_SESSION['userstate'] = 'ssnverified'; 33. } 34. initMenu(); 35. if (isset($_SESSION['userstate'])) return 0; 36. if ($_SESSION['userstate'] == 'confirmssn') { 37. themeHeader(); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Isset Errors
-Original Message- From: Davide Bernard [mailto:[EMAIL PROTECTED] Sent: 09 May 2007 15:18 To: php-general@lists.php.net Subject: [PHP] Isset Errors Anyone got any suggestions on getting rid of these errors below? [Wed May 09 08:59:05 2007] [error] [client 192.168.225.246] PHP Notice: Undefined index: userstate in /srv/www/htdocs/resetpw.php on line 31, referer: https://ams.unt.edu/resetpw.php [Wed May 09 08:59:05 2007] [error] [client 192.168.225.246] PHP Notice: Undefined index: userstate in /srv/www/htdocs/resetpw.php on line 36, referer: https://ams.unt.edu/resetpw.php Here's the lines of code I am getting the errors in PHP 5...Where can I insert some code to define 'userstate' ? 24. if (identifyUser()) { 25. if ((isset($_SESSION['clientinfo']['ssn'][0]) strcmp('9', $_SESSION['clientinfo']['ssn'][0])) 26. || isset($_SESSION['clientsinfo'])) { 27. $_SESSION['userstate'] = 'confirmssn'; 28. } else { 29. $_SESSION['userstate'] = 'ssnverified'; 30. } 31. } elseif ($_SESSION['userstate'] == 'confirmssn' confirmSSN()) { 32. $_SESSION['userstate'] = 'ssnverified'; 33. } 34. initMenu(); 35. if (isset($_SESSION['userstate'])) return 0; 36. if ($_SESSION['userstate'] == 'confirmssn') { 37. themeHeader(); If identifyUser() returns false, $_SESSION['userstate'] is not defined. Edward -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Isset Errors
On Wed, May 9, 2007 9:17 am, Davide Bernard wrote: Anyone got any suggestions on getting rid of these errors below? [Wed May 09 08:59:05 2007] [error] [client 192.168.225.246] PHP Notice: Undefined index: userstate in /srv/www/htdocs/resetpw.php on line 31, referer: https://ams.unt.edu/resetpw.php [Wed May 09 08:59:05 2007] [error] [client 192.168.225.246] PHP Notice: Undefined index: userstate in /srv/www/htdocs/resetpw.php on line 36, referer: https://ams.unt.edu/resetpw.php Here's the lines of code I am getting the errors in PHP 5...Where can I insert some code to define 'userstate' ? 24. if (identifyUser()) { 25. if ((isset($_SESSION['clientinfo']['ssn'][0]) strcmp('9', $_SESSION['clientinfo']['ssn'][0])) 26. || isset($_SESSION['clientsinfo'])) { 27. $_SESSION['userstate'] = 'confirmssn'; 28. } else { 29. $_SESSION['userstate'] = 'ssnverified'; 30. } 31. } elseif ($_SESSION['userstate'] == 'confirmssn' confirmSSN()) { elseif (isset($_SESSION['userstate']) $_SESSION['userstate'] == 'confirmssn' confirmSSN()){ 32. $_SESSION['userstate'] = 'ssnverified'; 33. } 34. initMenu(); 35. if (isset($_SESSION['userstate'])) return 0; 36. if ($_SESSION['userstate'] == 'confirmssn') { 37. themeHeader(); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- 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] isset
# [EMAIL PROTECTED] / 2007-04-17 13:59:39 +0200: snip The count is maintained internally as items are added/removed, and it is an O(1) operation for PHP to count the array, as it already knows the answer and just returns it. /snip Hi nothing to do with the actual topic, i am just wondering how you get this internals information you all seem to know so much about that's the whatsinside compulsive/obsessive personality disorder. it is very interesting and i'd like to add it to some of my late night reading if possible :) get ready for an allnighter, http://marc.info/ awaits you. -- How many Vietnam vets does it take to screw in a light bulb? You don't know, man. You don't KNOW. Cause you weren't THERE. http://bash.org/?255991 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] isset
snip The count is maintained internally as items are added/removed, and it is an O(1) operation for PHP to count the array, as it already knows the answer and just returns it. /snip Hi nothing to do with the actual topic, i am just wondering how you get this internals information you all seem to know so much about, it is very interesting and i'd like to add it to some of my late night reading if possible :) Regards, Tim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset
Tim wrote: snip The count is maintained internally as items are added/removed, and it is an O(1) operation for PHP to count the array, as it already knows the answer and just returns it. /snip Hi nothing to do with the actual topic, i am just wondering how you get this internals information you all seem to know so much about, it is very interesting and i'd like to add it to some of my late night reading if possible :) Just guessing, but I'd say probably the source code. That's where most of the internals of PHP are documented. ;) -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset
On Tue, 2007-04-17 at 13:14 +0100, Stut wrote: Tim wrote: snip The count is maintained internally as items are added/removed, and it is an O(1) operation for PHP to count the array, as it already knows the answer and just returns it. /snip Hi nothing to do with the actual topic, i am just wondering how you get this internals information you all seem to know so much about, it is very interesting and i'd like to add it to some of my late night reading if possible :) Just guessing, but I'd say probably the source code. That's where most of the internals of PHP are documented. ;) Several sources... the C source code as Stut has presumed :) Also from reading the PHP-DEV list where the source is often discussed. Additionally, some of it is from my early Computer Science background where there's a large focus on data structures and algorithms. 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] isset
On Tue, April 17, 2007 6:59 am, Tim wrote: snip The count is maintained internally as items are added/removed, and it is an O(1) operation for PHP to count the array, as it already knows the answer and just returns it. /snip Hi nothing to do with the actual topic, i am just wondering how you get this internals information you all seem to know so much about, it is very interesting and i'd like to add it to some of my late night reading if possible :) Invent a time machine, go back to the future, and subscribe to this list in 1997... Oh. Well, another option is to just read a heck of a lot of the archives, and the manual, and maybe the Internals list (not for the faint of heart) and the books, and maybe peruse some PHP source once in awhile and... There are many paths to enlightenment. Mostly all of them are long and torturous paths. :-) -- 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] isset
On Mon, April 16, 2007 8:06 pm, Robert Cummings wrote: On Mon, 2007-04-16 at 19:05 -0500, Richard Lynch wrote: On Mon, April 16, 2007 6:10 pm, Jochem Maas wrote: if I know it's an array I'll definitely use empty() over count() count() needs to actually count the items where as empty() can return false as soon as it finds a singel element ... maybe I'm mistaken - if so please put me right. You're wrong. The count is maintained internally as items are added/removed, and it is an O(1) operation for PHP to count the array, as it already knows the answer and just returns it. Fastest way to check if an array has elements... ?php if( $array ) { } ? IIRC, in olden days of PHP 3.x, if the first element was '0' or 0, then this test would result in FALSE... Which is not to say it's bad now, but to explain why an old hand might be leery of using it. -- 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] isset
At 12:16 PM -0500 4/15/07, Larry Garfield wrote: If you want your syntax to be a bit simpler, I frequently use helper functions along these lines: function http_get_int($var, $default=0) { return isset($_GET[$var]) ? (int) $_GET[$var] : $default; } if (http_get_int('var') ==5) { // Do stuff } Clean to read, easy defaults, (reasonably) type-safe, and E_NOTICE friendly. Larry: Slick. Thanks, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset
Richard Kurth wrote: What do you do when isset does not work? If I send data in a $_REQUEST['var'] like if (isset($_REQUEST['var'])) { } Put var has no data it still says it is set. Because $_REQUEST['var'] = and isset thinks is set I use this combination a lot: if ( isset($_GET['something']) !empty($_GET['something']) ) { // do something here with $_GET['something'] } -- Enjoy, Jim Lucas Different eyes see different things. Different hearts beat on different strings. But there are times for you and me when all such things agree. - Rush -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset
Jim Lucas wrote: Richard Kurth wrote: What do you do when isset does not work? If I send data in a $_REQUEST['var'] like if (isset($_REQUEST['var'])) { } Put var has no data it still says it is set. Because $_REQUEST['var'] = and isset thinks is set I use this combination a lot: if ( isset($_GET['something']) !empty($_GET['something']) ) { // do something here with $_GET['something'] } The isset is a pointless waste of cycles. -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset
Robert Cummings wrote: On Mon, 2007-04-16 at 09:27 -0700, Jim Lucas wrote: Stut wrote: Jim Lucas wrote: Richard Kurth wrote: What do you do when isset does not work? If I send data in a $_REQUEST['var'] like if (isset($_REQUEST['var'])) { } Put var has no data it still says it is set. Because $_REQUEST['var'] = and isset thinks is set I use this combination a lot: if ( isset($_GET['something']) !empty($_GET['something']) ) { // do something here with $_GET['something'] } The isset is a pointless waste of cycles. -Stut well, as the OP said, he wants to know when the variable has a value other the . So, to check for that you have to do something like this right? if ( $var != '' ) {} if ( strlen($var) 0 ) {} if ( !empty($var) ) {} ... a number of other ideas come to mind, but none of them will work, because they will always product a E_NOTICE warning. You COULD always use empty() prefixed with an @ to quiet the E_NOTICE, Stut wouldn't do that... especially not after calling isset() a waste of cycles. using the @ to suppress warnings/errors still invokes the error system, and that includes any error handler you've custom hooked. Maybe Stut just writes bad code ;) ;) Cheers, Rob. I wouldn't say bad code, but I might say exceptionally noisy code :P -- Enjoy, Jim Lucas Different eyes see different things. Different hearts beat on different strings. But there are times for you and me when all such things agree. - Rush -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset
At 4:08 PM +0100 4/16/07, Stut wrote: Jim Lucas wrote: Richard Kurth wrote: What do you do when isset does not work? If I send data in a $_REQUEST['var'] like if (isset($_REQUEST['var'])) { } Put var has no data it still says it is set. Because $_REQUEST['var'] = and isset thinks is set I use this combination a lot: if ( isset($_GET['something']) !empty($_GET['something']) ) { // do something here with $_GET['something'] } The isset is a pointless waste of cycles. -Stut I've been accuse of that too, but what's your solution? Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset
tedd wrote: At 4:08 PM +0100 4/16/07, Stut wrote: Jim Lucas wrote: Richard Kurth wrote: What do you do when isset does not work? If I send data in a $_REQUEST['var'] like if (isset($_REQUEST['var'])) { } Put var has no data it still says it is set. Because $_REQUEST['var'] = and isset thinks is set I use this combination a lot: if ( isset($_GET['something']) !empty($_GET['something']) ) { // do something here with $_GET['something'] } The isset is a pointless waste of cycles. -Stut I've been accuse of that too, but what's your solution? In the above example, if (isset($_GET['something']) !empty($_GET['something'])) { is the same as... if (!empty($_GET['something'])) { So, in that particular line of code the isset is a pointless waste of cycles. -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset
Stut wrote: tedd wrote: At 4:08 PM +0100 4/16/07, Stut wrote: Jim Lucas wrote: Richard Kurth wrote: What do you do when isset does not work? If I send data in a $_REQUEST['var'] like if (isset($_REQUEST['var'])) { } Put var has no data it still says it is set. Because $_REQUEST['var'] = and isset thinks is set I use this combination a lot: if ( isset($_GET['something']) !empty($_GET['something']) ) { // do something here with $_GET['something'] } The isset is a pointless waste of cycles. -Stut I've been accuse of that too, but what's your solution? In the above example, if (isset($_GET['something']) !empty($_GET['something'])) { is the same as... if (!empty($_GET['something'])) { So, in that particular line of code the isset is a pointless waste of cycles. -Stut these two lines are not the same infact, with the first, you will not get a E_NOTICE warning, but with the second you will. -- Enjoy, Jim Lucas Different eyes see different things. Different hearts beat on different strings. But there are times for you and me when all such things agree. - Rush -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset
that was actually my point. :) -afan Stut wrote: tedd wrote: At 4:08 PM +0100 4/16/07, Stut wrote: Jim Lucas wrote: Richard Kurth wrote: What do you do when isset does not work? If I send data in a $_REQUEST['var'] like if (isset($_REQUEST['var'])) { } Put var has no data it still says it is set. Because $_REQUEST['var'] = and isset thinks is set I use this combination a lot: if ( isset($_GET['something']) !empty($_GET['something']) ) { // do something here with $_GET['something'] } The isset is a pointless waste of cycles. -Stut I've been accuse of that too, but what's your solution? In the above example, if (isset($_GET['something']) !empty($_GET['something'])) { is the same as... if (!empty($_GET['something'])) { So, in that particular line of code the isset is a pointless waste of cycles. -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset
Stut wrote: Jim Lucas wrote: Richard Kurth wrote: What do you do when isset does not work? If I send data in a $_REQUEST['var'] like if (isset($_REQUEST['var'])) { } Put var has no data it still says it is set. Because $_REQUEST['var'] = and isset thinks is set I use this combination a lot: if ( isset($_GET['something']) !empty($_GET['something']) ) { // do something here with $_GET['something'] } The isset is a pointless waste of cycles. -Stut well, as the OP said, he wants to know when the variable has a value other the . So, to check for that you have to do something like this right? if ( $var != '' ) {} if ( strlen($var) 0 ) {} if ( !empty($var) ) {} ... a number of other ideas come to mind, but none of them will work, because they will always product a E_NOTICE warning. You COULD always use empty() prefixed with an @ to quiet the E_NOTICE, but, me, I could/would possibly miss that when scanning the code. I would however see the isset() !empty() bit of code. And the amount of time that you save by not using isset(), well, lets just say that if it affected the time of your apps performance, I think you have other things to worry about first. Just for example. The current project that just took over has about 60,000 lines of code. Doing a quick grep -ri 'isset' * on the dir returns about 475 instances of that function call. Many of which I have added to the system to get rid of E_NOTICE warnings, for the simple fact that I wanted to set error reporting to E_ALL. Bad mistake, over half the scripts fire off warnings left and right, because all he was doing for checking was !empty() if ( $var ) {} or if ( $var != '' ) {} calls all over the place. There are two ways that I have found to get rid of the notices. Example #1 if ( isset($_GET['something']) !empty($_GET['something']) ) { // do something here with $_GET['something'] } Example #2 if ( @!empty($_GET['something']) ) { // do something here with $_GET['something'] } Other suggestions would be gladly accepted. -- Enjoy, Jim Lucas Different eyes see different things. Different hearts beat on different strings. But there are times for you and me when all such things agree. - Rush -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset
On Apr 16, 2007, at 11:27 AM, Jim Lucas wrote: Stut wrote: Jim Lucas wrote: Richard Kurth wrote: What do you do when isset does not work? If I send data in a $_REQUEST['var'] like if (isset($_REQUEST['var'])) { } Put var has no data it still says it is set. Because $_REQUEST ['var'] = and isset thinks is set I use this combination a lot: if ( isset($_GET['something']) !empty($_GET['something']) ) { // do something here with $_GET['something'] } The isset is a pointless waste of cycles. -Stut well, as the OP said, he wants to know when the variable has a value other the . So, to check for that you have to do something like this right? if ( $var != '' ) {} if ( strlen($var) 0 ) {} if ( !empty($var) ) {} ... a number of other ideas come to mind, but none of them will work, because they will always product a E_NOTICE warning. empty() does NOT produce an E_NOTICE if the variable is not set. That's one of the things it considers as empty. And why I always do !empty($foo) then check for a value such as (! empty($foo) $foo == $bar) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset
On Mon, 2007-04-16 at 09:27 -0700, Jim Lucas wrote: Stut wrote: Jim Lucas wrote: Richard Kurth wrote: What do you do when isset does not work? If I send data in a $_REQUEST['var'] like if (isset($_REQUEST['var'])) { } Put var has no data it still says it is set. Because $_REQUEST['var'] = and isset thinks is set I use this combination a lot: if ( isset($_GET['something']) !empty($_GET['something']) ) { // do something here with $_GET['something'] } The isset is a pointless waste of cycles. -Stut well, as the OP said, he wants to know when the variable has a value other the . So, to check for that you have to do something like this right? if ( $var != '' ) {} if ( strlen($var) 0 ) {} if ( !empty($var) ) {} ... a number of other ideas come to mind, but none of them will work, because they will always product a E_NOTICE warning. You COULD always use empty() prefixed with an @ to quiet the E_NOTICE, Stut wouldn't do that... especially not after calling isset() a waste of cycles. using the @ to suppress warnings/errors still invokes the error system, and that includes any error handler you've custom hooked. Maybe Stut just writes bad code ;) ;) 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] isset
Jim Lucas wrote: Stut wrote: tedd wrote: At 4:08 PM +0100 4/16/07, Stut wrote: Jim Lucas wrote: Richard Kurth wrote: What do you do when isset does not work? If I send data in a $_REQUEST['var'] like if (isset($_REQUEST['var'])) { } Put var has no data it still says it is set. Because $_REQUEST['var'] = and isset thinks is set I use this combination a lot: if ( isset($_GET['something']) !empty($_GET['something']) ) { // do something here with $_GET['something'] } The isset is a pointless waste of cycles. -Stut I've been accuse of that too, but what's your solution? In the above example, if (isset($_GET['something']) !empty($_GET['something'])) { is the same as... if (!empty($_GET['something'])) { So, in that particular line of code the isset is a pointless waste of cycles. -Stut these two lines are not the same infact, with the first, you will not get a E_NOTICE warning, but with the second you will. No you won't. The empty function does not raise a notice if its argument does not exist. From http://php.net/empty... empty() is the opposite of (boolean) var, except that no warning is generated when the variable is not set. -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset
Stut wrote: Jim Lucas wrote: Stut wrote: tedd wrote: At 4:08 PM +0100 4/16/07, Stut wrote: Jim Lucas wrote: Richard Kurth wrote: What do you do when isset does not work? If I send data in a $_REQUEST['var'] like if (isset($_REQUEST['var'])) { } Put var has no data it still says it is set. Because $_REQUEST['var'] = and isset thinks is set I use this combination a lot: if ( isset($_GET['something']) !empty($_GET['something']) ) { // do something here with $_GET['something'] } The isset is a pointless waste of cycles. -Stut I've been accuse of that too, but what's your solution? In the above example, if (isset($_GET['something']) !empty($_GET['something'])) { is the same as... if (!empty($_GET['something'])) { So, in that particular line of code the isset is a pointless waste of cycles. -Stut these two lines are not the same infact, with the first, you will not get a E_NOTICE warning, but with the second you will. No you won't. The empty function does not raise a notice if its argument does not exist. From http://php.net/empty... empty() is the opposite of (boolean) var, except that no warning is generated when the variable is not set. -Stut Interesting, have not looked at the empty() man page in a long time. It use to through E_NOTICE warnings, as far back as I can remember back in 1999, and 2000 I wonder if they changed it, or the person that told me to do it that way was mistaken. my mistake. But, as you can tell, others were under the same impression as I. -- Enjoy, Jim Lucas Different eyes see different things. Different hearts beat on different strings. But there are times for you and me when all such things agree. - Rush -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset
On Mon, 2007-04-16 at 18:16 +0100, Stut wrote: Jim Lucas wrote: Stut wrote: tedd wrote: At 4:08 PM +0100 4/16/07, Stut wrote: Jim Lucas wrote: Richard Kurth wrote: What do you do when isset does not work? If I send data in a $_REQUEST['var'] like if (isset($_REQUEST['var'])) { } Put var has no data it still says it is set. Because $_REQUEST['var'] = and isset thinks is set I use this combination a lot: if ( isset($_GET['something']) !empty($_GET['something']) ) { // do something here with $_GET['something'] } The isset is a pointless waste of cycles. -Stut I've been accuse of that too, but what's your solution? In the above example, if (isset($_GET['something']) !empty($_GET['something'])) { is the same as... if (!empty($_GET['something'])) { So, in that particular line of code the isset is a pointless waste of cycles. -Stut these two lines are not the same infact, with the first, you will not get a E_NOTICE warning, but with the second you will. No you won't. The empty function does not raise a notice if its argument does not exist. From http://php.net/empty... empty() is the opposite of (boolean) var, except that no warning is generated when the variable is not set. Bleh, my mistake... I'm so adverse to empty() I forgot it doesn't generate notices. 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] isset
On Apr 16, 2007, at 12:30 PM, Robert Cummings wrote: [snip] Bleh, my mistake... I'm so adverse to empty() I forgot it doesn't generate notices. Lemme guess... You don't like empty() because it thinks null/0/'' is empty? Or is there some other reason? Agreed, it can be tricky if you just use it everywhere, but for most things, especially replacing a if (isset($foo) $foo != 0/null/''/array()) {} with if (!empty($foo)) makes my life a little easier. Especially checking for empty arrays since foreach on an empty array will throw a notice or warning, I forget which atm. Of course if null/0/'' are considered valid values in your code then you're pretty much stuck with isset() and checking for the value. And doesn't it also consider 'null' (the string) as empty? Seems like I've read folks complaining that returns from a database that are set to null get missed also... but since I don't have any code that considers null a useful value it's never been a problem for me. Ed -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset
On Mon, 2007-04-16 at 13:16 -0500, Edward Vermillion wrote: On Apr 16, 2007, at 12:30 PM, Robert Cummings wrote: [snip] Bleh, my mistake... I'm so adverse to empty() I forgot it doesn't generate notices. Strings only containing only spaces are not empty. Strings containing a 0 are empty. It's crap for almost any kind of validation routine. It's one of those useless, magical, shoot newbies in the toes functions. But then I guess to each their own :) 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] isset
On Apr 16, 2007, at 1:28 PM, Robert Cummings wrote: On Mon, 2007-04-16 at 13:16 -0500, Edward Vermillion wrote: On Apr 16, 2007, at 12:30 PM, Robert Cummings wrote: [snip] Bleh, my mistake... I'm so adverse to empty() I forgot it doesn't generate notices. Strings only containing only spaces are not empty. Strings containing a 0 are empty. It's crap for almost any kind of validation routine. It's one of those useless, magical, shoot newbies in the toes functions. But then I guess to each their own :) Strings containing spaces and 0's (and null), while technically not empty, may or may not have any meaning in your code outside of being empty or at least not interesting. That's why I qualified it with whether they have meaning in the code. I'll agree that it can cause problems if you're not paying attention, I've been bitten myself in the past by it. And those things can be hard to track down too. :P Ed -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset
Robert Cummings wrote: On Mon, 2007-04-16 at 09:27 -0700, Jim Lucas wrote: Stut wrote: Jim Lucas wrote: Richard Kurth wrote: What do you do when isset does not work? If I send data in a $_REQUEST['var'] like if (isset($_REQUEST['var'])) { } Put var has no data it still says it is set. Because $_REQUEST['var'] = and isset thinks is set I use this combination a lot: if ( isset($_GET['something']) !empty($_GET['something']) ) { // do something here with $_GET['something'] } The isset is a pointless waste of cycles. -Stut well, as the OP said, he wants to know when the variable has a value other the . So, to check for that you have to do something like this right? if ( $var != '' ) {} if ( strlen($var) 0 ) {} if ( !empty($var) ) {} ... a number of other ideas come to mind, but none of them will work, because they will always product a E_NOTICE warning. You COULD always use empty() prefixed with an @ to quiet the E_NOTICE, Stut wouldn't do that... especially not after calling isset() a waste of cycles. using the @ to suppress warnings/errors still invokes the error system, and that includes any error handler you've custom hooked. Maybe Stut just writes bad code ;) ;) I'm thinking I just know some parts of the language better than you lot. You guys really should try reading the manual before responding instead of just assuming it's the way you think it is. As far as my coding style goes, that's between me and my $DEITY, but let it be noted that even my production servers run with error_reporting as E_ALL (but logged to files and not displayed obviously). Knowing how isset and empty work is essential to enabling my style of coding PHP, which I've found works very well for me. -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset
On Sat, April 14, 2007 8:36 pm, Richard Kurth wrote: What do you do when isset does not work? If I send data in a $_REQUEST['var'] like if (isset($_REQUEST['var'])) { } Put var has no data it still says it is set. Because $_REQUEST['var'] = and isset thinks is set It *is* set. It just happens to be the empty string. That is VERY different from not being set at all. If you do not want to allow the empty string as a valid input, that should, imho, be handled by your data validation routines, which happen after your business logic of doing whatever based on isset() http://php.net/strlen is a good one for that. In other words, use isset() to decide what the user is trying to do first. Then use data validation to decide if they have provided valid/suitable input. If the input is egregious enough (i.e., no normal human would ever generate that state) you can respond differently with, say, die(hacker); -- 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] isset
On Sun, April 15, 2007 12:07 pm, [EMAIL PROTECTED] wrote: I have E_NOTICE turned off. :) Your first mistake. :-) E_NOTICE on is a royal pain at first, but will catch bugs for you, and save you development time in the long run. Turn it on for your next new project and try it. -- 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] isset
-Message d'origine- De : Robert Cummings [mailto:[EMAIL PROTECTED] Envoyé : lundi 16 avril 2007 20:28 À : Edward Vermillion Cc : php Lists Objet : Re: [PHP] isset On Mon, 2007-04-16 at 13:16 -0500, Edward Vermillion wrote: On Apr 16, 2007, at 12:30 PM, Robert Cummings wrote: [snip] Bleh, my mistake... I'm so adverse to empty() I forgot it doesn't generate notices. Strings only containing only spaces are not empty. Strings containing a 0 are empty. It's crap for almost any kind of validation routine. It's one of those useless, magical, shoot newbies in the toes functions. But then I guess to each their own :) What about in the following context? $arr = array(); If (!empty($arr)) { } This is where i have found it to be the most usefull... tim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset
On Mon, April 16, 2007 11:12 am, tedd wrote: I've been accuse of that too, but what's your solution? *MY* solution: Don't use empty because its behaviour changed wrt 0 in various versions, so it's just gonna bite you in the butt like it did me. :-) I generally do this basic algorithm: #1 Use isset() to see what came in as inputs, to decide basic business logic for large-scale chunks of code Also use specific values with == for simple if/else or switch setup here #2 Within an isset() (and possible == 'foo' block) Check the validity of the data *WAY* more than just empty preg_match with a white-list pattern is good ctype for specific data is good checking with strlen() (possibly with trim() first) is good typecasting any data that should be of a certain type is good checking inputs against a static list of valid inputs is good #3 Still within the block, Prep input data for output formats as needed for this section: $foo_sql = mysql_real_escape_string($foo, $connection); $foo_html = htmlentities($foo); $foo_json = json_encode(foo); Only after all that is done do I start actually doing fine-tuned business logic of the body of my code. I may end up repeating the same large structure I had above, to decide what code to run, or maybe it will be a different structure, depending on what the script does. But all my data is clean and prepped at this point, so I can just use it. Within that code, if I'm writing an SQL query, I can just do: $query = whatever SQL blah blah '$foo_sql' blah ; If I'm going to echo out $foo, I can just do: echo whatever blah blah $foo_html blah ; I just tossed in JSON even though I've never used it in my life so far, but I presume it would be like: ?script type=text/javascript !-- var foo = ?php echo $foo_json?; -- /script ?php I'm not claiming this is the best way ever, or will work for the next big thing with 50 developers, but it works well for my needs of simple maintainable scripts in a one-man shop. YMMV -- 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] isset
On Mon, April 16, 2007 5:35 pm, Tim Earl wrote: What about in the following context? $arr = array(); If (!empty($arr)) { } This is where i have found it to be the most usefull... If I'm already certain that it's an array, I just use 'count' personally. 'empty' takes a mixed data type, and could return TRUE for, say, 'foo' even though you are expecting an array there. I think it's a better practice to use the right weapon and use count() on an array to see if it's empty or not. -- 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] isset
On Mon, April 16, 2007 11:18 am, Jim Lucas wrote: these two lines are not the same infact, with the first, you will not get a E_NOTICE warning, but with the second you will. I dunno what you are thinking of, but the manual says: empty() is the opposite of (boolean) var, except that no warning is generated when the variable is not set. I am reasonably certain that empty, like isset is not, in fact, a function, but is a language construct (like if and foreach) and it does not attempt to use the variable per se, so does not generate an E_NOTICE. I am also reasonably certain that this has been true since empty debuted in the language, but won't swear to that in court. -- 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] isset
Richard Lynch wrote: On Mon, April 16, 2007 5:35 pm, Tim Earl wrote: What about in the following context? $arr = array(); If (!empty($arr)) { } This is where i have found it to be the most usefull... If I'm already certain that it's an array, I just use 'count' personally. 'empty' takes a mixed data type, and could return TRUE for, say, 'foo' even though you are expecting an array there. I think it's a better practice to use the right weapon and use count() on an array to see if it's empty or not. php -r 'var_dump(count(foo));' outputs: int(1) so my strategy is usually if (!empty($r) is_array($r)) { // good to go. } if I know it's an array I'll definitely use empty() over count() count() needs to actually count the items where as empty() can return false as soon as it finds a singel element ... maybe I'm mistaken - if so please put me right. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset
I've been using empty() for about 5 years, obeying the rules for empty() in the php manual Appendix P. PHP type comparison tables and have never seen it generate any type of error message. If you guys know of at least one exception, please clue us in on it. Jim Lucas wrote: Stut wrote: tedd wrote: At 4:08 PM +0100 4/16/07, Stut wrote: Jim Lucas wrote: Richard Kurth wrote: What do you do when isset does not work? If I send data in a $_REQUEST['var'] like if (isset($_REQUEST['var'])) { } Put var has no data it still says it is set. Because $_REQUEST['var'] = and isset thinks is set I use this combination a lot: if ( isset($_GET['something']) !empty($_GET['something']) ) { // do something here with $_GET['something'] } The isset is a pointless waste of cycles. -Stut I've been accuse of that too, but what's your solution? In the above example, if (isset($_GET['something']) !empty($_GET['something'])) { is the same as... if (!empty($_GET['something'])) { So, in that particular line of code the isset is a pointless waste of cycles. -Stut these two lines are not the same infact, with the first, you will not get a E_NOTICE warning, but with the second you will. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset
On Mon, April 16, 2007 6:10 pm, Jochem Maas wrote: if I know it's an array I'll definitely use empty() over count() count() needs to actually count the items where as empty() can return false as soon as it finds a singel element ... maybe I'm mistaken - if so please put me right. You're wrong. The count is maintained internally as items are added/removed, and it is an O(1) operation for PHP to count the array, as it already knows the answer and just returns it. -- 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] isset
On Mon, 2007-04-16 at 19:05 -0500, Richard Lynch wrote: On Mon, April 16, 2007 6:10 pm, Jochem Maas wrote: if I know it's an array I'll definitely use empty() over count() count() needs to actually count the items where as empty() can return false as soon as it finds a singel element ... maybe I'm mistaken - if so please put me right. You're wrong. The count is maintained internally as items are added/removed, and it is an O(1) operation for PHP to count the array, as it already knows the answer and just returns it. Fastest way to check if an array has elements... ?php if( $array ) { } ? 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] isset
Afan Pasalic wrote: Jochem Maas wrote: Richard Kurth wrote: What do you do when isset does not work? If I send data in a $_REQUEST['var'] like if (isset($_REQUEST['var'])) { } Put var has no data it still says it is set. Because $_REQUEST['var'] = and isset thinks is set php -r ' $r = array(foo = ); var_dump(isset($r[foo]),empty($r[foo]));' so empty() should give you the result your looking for ... some tips: 1. generally use $_GET or $_POST in preference to $_REQUEST 2. be specific about your input validation, e.g.: if (isset($_GET['var']) ($_GET['var'] == 'foo')) { echo got it!; } I always wondered about this. if $_GET['var'] == 'foo' is true, isn't automatically isset($_GET['var']) true too? I mean, isn't if ($_GET['var'] == 'foo') { echo got it!; } just enough? it doesn't cover the situation where $_GET['var'] doesn't exist, and using uninitialized var is not recommended. of course it's your call whether you write/run code that spits out E_NOTICEs all over the place due to usage of uninitialized vars. -afan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset
Afan Pasalic wrote: Jochem Maas wrote: Richard Kurth wrote: What do you do when isset does not work? If I send data in a $_REQUEST['var'] like if (isset($_REQUEST['var'])) { } Put var has no data it still says it is set. Because $_REQUEST['var'] = and isset thinks is set php -r ' $r = array(foo = ); var_dump(isset($r[foo]),empty($r[foo]));' so empty() should give you the result your looking for ... some tips: 1. generally use $_GET or $_POST in preference to $_REQUEST 2. be specific about your input validation, e.g.: if (isset($_GET['var']) ($_GET['var'] == 'foo')) { echo got it!; } I always wondered about this. if $_GET['var'] == 'foo' is true, isn't automatically isset($_GET['var']) true too? I mean, isn't if ($_GET['var'] == 'foo') { echo got it!; } just enough? it doesn't cover the situation where $_GET['var'] doesn't exist, and using uninitialized var is not recommended. of course it's your call whether you write/run code that spits out E_NOTICEs all over the place due to usage of uninitialized vars. not quite sure. if $_GET['var'] doesn't exists it's DEFINITLY not equal to 'foo', right? how I understand: clause one: isset($_GET['var']) clause two: ($_GET['var'] == 'foo') if clause two is true, clause one MUST be true. if clause one is true, clause two could be true or false. means, if I look for solutions where ($_GET['var'] == 'foo') they wil lautomaticaly cover isset($_GET['var']) part. if ($_GET['var'] != 'foo') I erally do not care isset($_GET['var']) or !isset($_GET['var']). or I'm missing something here? I have E_NOTICE turned off. :) thanks. -afan -afan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset
On Sunday 15 April 2007 12:07 pm, [EMAIL PROTECTED] wrote: of course it's your call whether you write/run code that spits out E_NOTICEs all over the place due to usage of uninitialized vars. not quite sure. if $_GET['var'] doesn't exists it's DEFINITLY not equal to 'foo', right? how I understand: clause one: isset($_GET['var']) clause two: ($_GET['var'] == 'foo') if clause two is true, clause one MUST be true. if clause one is true, clause two could be true or false. means, if I look for solutions where ($_GET['var'] == 'foo') they wil lautomaticaly cover isset($_GET['var']) part. if ($_GET['var'] != 'foo') I erally do not care isset($_GET['var']) or !isset($_GET['var']). or I'm missing something here? I have E_NOTICE turned off. :) And right there is your first mistake. The only time to not have E_NOTICE on is when you're using legacy code that isn't E_NOTICE compliant and you don't have the time to upgrade it to be compliant. Developing without E_NOTICE means you're telling the computer it's OK, let me just randomly guess where this bug or security hole or random typo is. *Bad* idea. *Always* develop in the tightest, most restricted, most nit-picky setting you can get, regardless of the language. If you want your syntax to be a bit simpler, I frequently use helper functions along these lines: function http_get_int($var, $default=0) { return isset($_GET[$var]) ? (int) $_GET[$var] : $default; } if (http_get_int('var') ==5) { // Do stuff } Clean to read, easy defaults, (reasonably) type-safe, and E_NOTICE friendly. -- Larry Garfield AIM: LOLG42 [EMAIL PROTECTED] ICQ: 6817012 If nature has made any one thing less susceptible than all others of exclusive property, it is the action of the thinking power called an idea, which an individual may exclusively possess as long as he keeps it to himself; but the moment it is divulged, it forces itself into the possession of every one, and the receiver cannot dispossess himself of it. -- Thomas Jefferson -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] isset
how I understand: clause one: isset($_GET['var']) clause two: ($_GET['var'] == 'foo') if clause two is true, clause one MUST be true. if clause one is true, clause two could be true or false. means, if I look for solutions where ($_GET['var'] == 'foo') they wil lautomaticaly cover isset($_GET['var']) part. if ($_GET['var'] != 'foo') I erally do not care isset($_GET['var']) or !isset($_GET['var']). If you are looking for isset($_GET['var']) to return true if the value exists, but may be null, you can always use if (isset($_GET['var']) || is_null($_GET['var])) Albeit, I'm unsure if this will generate a warning if $_GET['var'] doesn't exist for the is_null() call. And in this case, I believe it would be appropriate to ignore that one warning. -Logan -Original Message- From: Larry Garfield [mailto:[EMAIL PROTECTED] Sent: Sunday, April 15, 2007 1:17 PM To: [EMAIL PROTECTED] Subject: Re: [PHP] isset On Sunday 15 April 2007 12:07 pm, [EMAIL PROTECTED] wrote: of course it's your call whether you write/run code that spits out E_NOTICEs all over the place due to usage of uninitialized vars. not quite sure. if $_GET['var'] doesn't exists it's DEFINITLY not equal to 'foo', right? or I'm missing something here? I have E_NOTICE turned off. :) And right there is your first mistake. The only time to not have E_NOTICE on is when you're using legacy code that isn't E_NOTICE compliant and you don't have the time to upgrade it to be compliant. Developing without E_NOTICE means you're telling the computer it's OK, let me just randomly guess where this bug or security hole or random typo is. *Bad* idea. *Always* develop in the tightest, most restricted, most nit-picky setting you can get, regardless of the language. If you want your syntax to be a bit simpler, I frequently use helper functions along these lines: function http_get_int($var, $default=0) { return isset($_GET[$var]) ? (int) $_GET[$var] : $default; } if (http_get_int('var') ==5) { // Do stuff } Clean to read, easy defaults, (reasonably) type-safe, and E_NOTICE friendly. -- Larry Garfield AIM: LOLG42 [EMAIL PROTECTED] ICQ: 6817012 If nature has made any one thing less susceptible than all others of exclusive property, it is the action of the thinking power called an idea, which an individual may exclusively possess as long as he keeps it to himself; but the moment it is divulged, it forces itself into the possession of every one, and the receiver cannot dispossess himself of it. -- Thomas Jefferson -- 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
[PHP] isset
What do you do when isset does not work? If I send data in a $_REQUEST['var'] like if (isset($_REQUEST['var'])) { } Put var has no data it still says it is set. Because $_REQUEST['var'] = and isset thinks is set
Re: [PHP] isset
Richard Kurth wrote: What do you do when isset does not work? If I send data in a $_REQUEST['var'] like if (isset($_REQUEST['var'])) { } Put var has no data it still says it is set. Because $_REQUEST['var'] = and isset thinks is set php -r ' $r = array(foo = ); var_dump(isset($r[foo]),empty($r[foo]));' so empty() should give you the result your looking for ... some tips: 1. generally use $_GET or $_POST in preference to $_REQUEST 2. be specific about your input validation, e.g.: if (isset($_GET['var']) ($_GET['var'] == 'foo')) { echo got it!; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] isset or array_key_exists?
Please, answer: what construction works faster: if ( isset ( $result [$i] [key] ) ) {do something; } or if ( array_key_exists ( key, $result [$i] ) ) {do something; } ? Nikolay
[PHP] isset
I often use this type of construct $cmd = $_POST['cmd']; if ($cmd == null) { // do default but this throws a notice if the ['cmd'] index is not defined. ugly. using if (isset($_POST['cmd'] ) { $cmd = $_POST['cmd']; } seems lengthy. is there a way around this? i tried using $cmd = @ $_POST['cmd']; to suppress errors but didnt seem to have ay effect. tx. -- ___ David DC Collier mobile business creator [EMAIL PROTECTED] skype: d3ntaku http://www.pikkle.com +81 (0)90-7414-6107 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset
D_C wrote: I often use this type of construct $cmd = $_POST['cmd']; if ($cmd == null) { // do default but this throws a notice if the ['cmd'] index is not defined. ugly. using if (isset($_POST['cmd'] ) { $cmd = $_POST['cmd']; } seems lengthy. is there a way around this? i tried using $cmd = @ $_POST['cmd']; to suppress errors but didnt seem to have ay effect. You could maybe put the @ in front of the $cmd: @$cmd = $_POST['cmd']; However, I think it would be most clear to do: $cmd = isset($_POST['cmd']) ? $_POST['cmd'] : NULL; You can then rest assured that $cmd *IS* set in the rest of your script. It's a bit lengthy, but at least it's all on one concise line, and you can easily copy/paste and comment in/out the line. -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset
D_C wrote: I often use this type of construct $cmd = $_POST['cmd']; if ($cmd == null) { // do default but this throws a notice if the ['cmd'] index is not defined. ugly. using if (isset($_POST['cmd'] ) { $cmd = $_POST['cmd']; } seems lengthy. is there a way around this? http://www.php.net/array-key-exists $cmd = array_key_exists('cmd',$_POST) ? $_POST['cmd'] : null; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] isset opposite
Hi there.. I am pretty new to PHP, and I am familiar with php isset option now i was wondering (I have looked at the PHP site - but can not find it) how can you check if something is not set? I need to test if a $_GET is not set (not just empty). thanks in advance! d -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset opposite
Hi there.. I am pretty new to PHP, and I am familiar with php isset option now i was wondering (I have looked at the PHP site - but can not find it) how can you check if something is not set? I need to test if a $_GET is not set (not just empty). thanks in advance! d I'm sure I'll be one of the many who says this: !isset The ! means not. You can use it with most of the functions like !empty (not empty). So you can use it like so: if (!isset($_GET[var])) { do stuff } -- --Matthew Sims --http://killermookie.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset opposite
On Tue, 16 Nov 2004 15:11:39 -0800, Dustin Krysak [EMAIL PROTECTED] wrote: how can you check if something is not set? !isset() -- Greg Donald Zend Certified Engineer http://gdconsultants.com/ http://destiney.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset opposite
On Nov 16, 2004, at 5:11 PM, Dustin Krysak wrote: Hi there.. I am pretty new to PHP, and I am familiar with php isset option now i was wondering (I have looked at the PHP site - but can not find it) how can you check if something is not set? I need to test if a $_GET is not set (not just empty). !array_key_exists('yourkey', $_GET); -ryan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset opposite
On Tue, 2004-11-16 at 15:11 -0800, Dustin Krysak wrote: Hi there.. I am pretty new to PHP, and I am familiar with php isset option now i was wondering (I have looked at the PHP site - but can not find it) how can you check if something is not set? I need to test if a $_GET is not set (not just empty). thanks in advance! d isset() returns a boolean. so...try, if (!isset($x)) -- /*** * Robby Russell | Owner.Developer.Geek * PLANET ARGON | www.planetargon.com * Portland, OR | [EMAIL PROTECTED] * 503.351.4730 | blog.planetargon.com * PHP/PostgreSQL Hosting Development *--- Now supporting PHP5 --- / signature.asc Description: This is a digitally signed message part
Re: [PHP] isset opposite
Thanks! perfect! d On 16-Nov-04, at 4:13 PM, Robby Russell wrote: On Tue, 2004-11-16 at 15:11 -0800, Dustin Krysak wrote: Hi there.. I am pretty new to PHP, and I am familiar with php isset option now i was wondering (I have looked at the PHP site - but can not find it) how can you check if something is not set? I need to test if a $_GET is not set (not just empty). thanks in advance! d isset() returns a boolean. so...try, if (!isset($x)) -- /*** * Robby Russell | Owner.Developer.Geek * PLANET ARGON | www.planetargon.com * Portland, OR | [EMAIL PROTECTED] * 503.351.4730 | blog.planetargon.com * PHP/PostgreSQL Hosting Development *--- Now supporting PHP5 --- / -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset opposite
On Tue, 2004-11-16 at 17:19 -0800, Dustin Krysak wrote: Thanks! perfect! d For future reference, just about any function that uses is at the beginning should return a boolean result. So if (is_array()) can also be checked with if (!is_array()) This should apply to all the php included functions that start with is. -Robby -- /*** * Robby Russell | Owner.Developer.Geek * PLANET ARGON | www.planetargon.com * Portland, OR | [EMAIL PROTECTED] * 503.351.4730 | blog.planetargon.com * PHP/PostgreSQL Hosting Development *--- Now supporting PHP5 --- / signature.asc Description: This is a digitally signed message part
Re: [PHP] isset opposite
Yeah as soon as I saw this example, I figured that was the case for example something like if (!empty()) and so on. d On 16-Nov-04, at 5:26 PM, Robby Russell wrote: On Tue, 2004-11-16 at 17:19 -0800, Dustin Krysak wrote: Thanks! perfect! d For future reference, just about any function that uses is at the beginning should return a boolean result. So if (is_array()) can also be checked with if (!is_array()) This should apply to all the php included functions that start with is. -Robby -- /*** * Robby Russell | Owner.Developer.Geek * PLANET ARGON | www.planetargon.com * Portland, OR | [EMAIL PROTECTED] * 503.351.4730 | blog.planetargon.com * PHP/PostgreSQL Hosting Development *--- Now supporting PHP5 --- / -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] ISSET problem with Form
If you use ISSET together with a hidden field when posting a form to itself to enter a second-state, is there a way of using it again to get to a third-state. Basically, I'm trying to convert a 3 file script into a single file and first I check to see if it's been submitted and then using ELSE I echo out the second form. But how do I use isset again? Do I need to unset the variable from the first stage of the form? If so, how do I do this and prevent the form going back to the first form state? I've had the script working with two states but can't get the third state working!!! Any help or alternative ideas much appreciated as this is causing me a serious headache!!! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] ISSET problem with Form
[snip] I've had the script working with two states but can't get the third state working!!! Any help or alternative ideas much appreciated as this is causing me a serious headache!!! [/snip] Sessions would be a better way to handle this. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] ISSET problem with Form
[snip] I'm new to PHP, so how would I go about using sessions? I assume one needs to update _SESSION['name'] = $name; with the state of the form and then use IF ? Then I'm stuck again! [/snip] start here http://www.php.net/session P.S. Always reply to the list, you may not get a response. Your e-mail was redirected to my SPAM folder as an unknown. I just happened to see it when looking for something else someone swore they sent me. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset() and !=NULL
David Risner [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Fri, 26 Mar 2004 10:40:43 -0800, Marcjon Louwersheimer [EMAIL PROTECTED] said: Is there an easier way to do isset($variable) AND $variable != NULL ? I use this alot in my if statements, and I was wondering if there's an easier way to do it, maybe with a single function? Oh and another question... how does if ($variable) work? When does it evaluate true? Check out the is_null function. Itd seems to combine the two. http://www.php.net/manual/en/function.is-null.php and http://www.php.net/manual/en/language.types.null.php#language.types.null.syntax As Rasmus noted, (!empty($var)) is a complete aquivalent to (isset($var) $var != null). I ran some more extensive tests which show the following: class MyClass { var $field = 123; function MyClass() {} } 1. $x = null; 2. $y = 0; 3. $z = ''; 4. $w = 'xyz'; 5. $t = 123; 6. $o = new MyClass(); 7. // $v is not set 1. isset($x) $x != NULL: [] 2. isset($y) $y != NULL: [] 3. isset($z) $z != NULL: [] 4. isset($w) $w != NULL: [1] 5. isset($t) $t != NULL: [1] 6. isset($o) $o != NULL: [1] 7. isset($v) $v != NULL: [] 1. isset($x): [] 2. isset($y): [1] 3. isset($z): [1] 4. isset($w): [1] 5. isset($t): [1] 6. isset($o): [1] 7. isset($v): [] 1. !empty($x): [] 2. !empty($y): [] 3. !empty($z): [] 4. !empty($w): [1] 5. !empty($t): [1] 6. !empty($o): [1] 7. !empty($v): [] 1. is_null($x): [1] 2. is_null($y): [] 3. is_null($z): [] 4. is_null($w): [] 5. is_null($t): [] 6. is_null($o): [] Notice: Undefined variable: v in c:\web\test.php on line 62 7. is_null($v): [1] Also, as you see is_null($var) throws a notice when the variable is not defined. Hope this helps ;) Regards, Dimiter
[PHP] isset() and !=NULL
Is there an easier way to do isset($variable) AND $variable != NULL ? I use this alot in my if statements, and I was wondering if there's an easier way to do it, maybe with a single function? Oh and another question... how does if ($variable) work? When does it evaluate true? -- Marcjon -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset() and !=NULL
if(!empty($variable)) On Fri, 26 Mar 2004, Marcjon Louwersheimer wrote: Is there an easier way to do isset($variable) AND $variable != NULL ? I use this alot in my if statements, and I was wondering if there's an easier way to do it, maybe with a single function? Oh and another question... how does if ($variable) work? When does it evaluate true? -- Marcjon -- 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] isset() and !=NULL
On Fri, 2004-03-26 at 13:46, Rasmus Lerdorf wrote: if(!empty($variable)) This will return false positives for cases where the variable has not been set to null but HAS been set to the empty string or to a 0? This isn't really the same as the OP requested. However, isset() also returns false for variables assigned null values and so he is fine with just isset() and skipping the check for != NULL. Contrast the following code and output: echo ' isset: ['.isset( $foo ).']'.\n; echo '!empty: ['.(!empty( $foo )).']'.\n; -- isset: [] -- !empty: [] - $foo = null; echo ' isset: ['.isset( $foo ).']'.\n; echo '!empty: ['.(!empty( $foo )).']'.\n; -- isset: [] -- !empty: [] - $foo = 0; echo ' isset: ['.isset( $foo ).']'.\n; echo '!empty: ['.(!empty( $foo )).']'.\n; -- isset: [1] -- !empty: [] - $foo = 0.0; echo ' isset: ['.isset( $foo ).']'.\n; echo '!empty: ['.(!empty( $foo )).']'.\n; -- isset: [1] -- !empty: [] - $foo = ''; echo ' isset: ['.isset( $foo ).']'.\n; echo '!empty: ['.(!empty( $foo )).']'.\n; -- isset: [1] -- !empty: [] - $foo = 'blah'; echo ' isset: ['.isset( $foo ).']'.\n; echo '!empty: ['.(!empty( $foo )).']'.\n; -- isset: [1] -- !empty: [1] - Cheers, Rob. On Fri, 26 Mar 2004, Marcjon Louwersheimer wrote: Is there an easier way to do isset($variable) AND $variable != NULL ? I use this alot in my if statements, and I was wondering if there's an easier way to do it, maybe with a single function? Oh and another question... how does if ($variable) work? When does it evaluate true? -- Marcjon -- .. | 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] isset() and !=NULL
On Fri, 26 Mar 2004 10:40:43 -0800, Marcjon Louwersheimer [EMAIL PROTECTED] said: Is there an easier way to do isset($variable) AND $variable != NULL ? I use this alot in my if statements, and I was wondering if there's an easier way to do it, maybe with a single function? Oh and another question... how does if ($variable) work? When does it evaluate true? Check out the is_null function. Itd seems to combine the two. http://www.php.net/manual/en/function.is-null.php and http://www.php.net/manual/en/language.types.null.php#language.types.null.syntax -- David G. Risner Software Engineer California State University, Los Angeles http://www.risner.org/david/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re[2]: [PHP] isset() question
Hello Jason, Sunday, February 15, 2004, 7:44:06 PM, you wrote: I feel the book you're learning from might not be the best out there! Especially as it uses the horrible if : else : endif notation, includes code on the same line as the PHP tags themselves JW What is horrible about that style? IMO doing this: Consistency. The majority of code you can download will not use this notation. Although PHP coding standards are subjective as best, you still won't find any advocating this technique. Pick a style and stick to it. It's usually best if that style at least matches something like the official PHP documentation. JW ?php if ($something) : ? To me this is a mess and I would never advocate this style. Code on the same line as a php delimiter does not make for easy reading. JW looks a lot neater than: JW ?php JW if ($something) { I wouldn't have done it like that either, although its closer. ?php if ($something) { ... } ? JW But whichever style a book chooses to use should not impact on one's decision JW as to whether it is a good book or not. Of course it does, especially when combined with the other factors I listed. If the book you're learning from doesn't teach good coding practise - what will? It's not something you're born with. -- Best regards, Richard Davey http://www.phpcommunity.org/wiki/296.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] isset() question
On 15 February 2004 18:30, Richard Davey wrote: I feel the book you're learning from might not be the best out there! Especially as it uses the horrible if : else : endif notation, I'd have to disagree with you on that one -- personally I think that's a very elegant and useful syntax, and all the scripts written for my applications use it. However, this is a matter of personal opinion, and the choice between the colonified syntax and the various brace styles should be down to what suits *you* best. Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re[2]: [PHP] isset() question
On Monday 16 February 2004 18:14, Richard Davey wrote: Consistency. With what? With whose idea of style/formatting? I doubt you will find consistency in the real between different programmers/organisations. If such consistency was there then PHP would've have only had to support a single formatting style/syntax. The majority of code you can download will not use this notation. As I was trying to point out in my example, that particular notation is most useful where you wish to output a block of raw HTML (just to be explicit, without the use of echo (or print)) with an if-then-else conditional or part of a while-loop or similar construct. Although PHP coding standards are subjective as best, I think the same could be said for many other programming languages. Only where the language does not allow any deviations from rigid formatting rules would you not have arguments/opinions over style of coding. you still won't find any advocating this technique. Pick a style and stick to it. It's usually best if that style at least matches something like the official PHP documentation. JW ?php if ($something) : ? To me this is a mess and I would never advocate this style. Code on the same line as a php delimiter does not make for easy reading. To me the alternative of escaping in and out of php over 3 or more lines is even more of a mess. JW But whichever style a book chooses to use should not impact on one's decision JW as to whether it is a good book or not. Of course it does, especially when combined with the other factors I listed. It should be judged by its substance (ie the other factors) and not style. All things being equal (ie the other factors) then yes by all means judge by style. But then who is the arbiter of style? As you said yourself (and I fully agree) it is subjective. If the book you're learning from doesn't teach good coding practise - what will? It's not something you're born with. Good coding techniques/practices/styles have their own books. Plus if you already have a programming background and you're just getting into PHP I doubt whether the coding style used in the book will have any influence on your already established coding style. Just as you can't judge a book by its cover, you should not judge a programming language book by its coding style. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* Q: How do you fix all Windows bugs at once? A: Type DELTREE /Y C:\WINDOWS */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re[4]: [PHP] isset() question
Hello Jason, Monday, February 16, 2004, 2:21:01 PM, you wrote: Consistency. JW With what? With whose idea of style/formatting? If you hadn't chopped off the rest of my paragraph you'd have the answer. JW I doubt you will find consistency in the real between different JW programmers/organisations. If such consistency was there then PHP would've JW have only had to support a single formatting style/syntax. You won't, but you will find standards that some people adhere to. Feel free to do whatever you like, I don't have to debug your code so it doesn't bother me :) JW To me the alternative of escaping in and out of php over 3 or more lines is JW even more of a mess. How is clearly structured code a mess? The line count is irrelevant. Your preferred version is a scramble of tags and code, mine is clearly defined per line, works in my IDE of choice (as well as others with brace matching) and follows the attempts out there of PHP coding standards (mostly inherited from the C++ fraternity). That's why *I* like it. We're not going to agree on this, but you're still wrong in saying the version I posted is messy; it couldn't get any cleaner even in an html escaping context. Each to their own. JW It should be judged by its substance (ie the other factors) and not style. All That's like saying a piece of art should not be judged in its use of colour, but on the image itself - when in actual fact, they're both as important as each other. Children (and indeed adults) pick up bad writing habits by reading sloppy prose, you implicitly learn the style in-front of you even if the message itself comes across loud and clear. I see no difference with code. You're saying if it works, what does it matter what it looks like. I don't agree, it matters a lot. JW Good coding techniques/practices/styles have their own books. Everything has its own book, that doesn't mean it shouldn't be encouraged/implied in the more beginner titles out there. It's their responsibility as well. They should teach how to avoid spaghetti coding and how to structure code so you can return to it a few years down the line and not think wtf is going on here?. JW Just as you can't judge a book by its cover, you should not judge a JW programming language book by its coding style. We can leave this here because this will continue going around in circles - but I strongly disagree. You can tell a LOT about the overall quality of a script by its coding style and structure - just because its printed in the pages of book I see no reason why they should be treated any differently. -- Best regards, Richard Davey http://www.phpcommunity.org/wiki/296.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] isset() question
The following script is from Kevin Yank's book (Sitepoint). When I test it _without_ entering a name in the text box and hit submit, the _next_ page loads - however the same page should load beacuse of the conditional if (!isset($name) ): . If I replace !isset() with empty() like if (empty($name)): and do not enter a name then the _same_ page loads which is what is supposed to happen. Why doesn't the call to !isset() with the negation mark loads the next page when a name is not entered? The script predates globals being turned off and it is below. Thank you. TR . html head title Sample Page /title /head body ?php if (!isset($name) ): ? !-- No name has been provided, so we prompt the user for one. -- form action=?=$PHP_SELF? method=get Please enter your name: input type=text name=name / input type=submit value=GO / /form ?php else: ? pYour name: ?=$name?/p pThis paragraph contains a a href=newpage.php?name=?=urlencode($name)?link/a that passes the name variable on to the next document./p ?php endif; ? /body /html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset() question
Hello Anthony, Sunday, February 15, 2004, 4:43:12 PM, you wrote: AR Why doesn't the call to !isset() with the negation mark loads the next page AR when a name is not entered? Because it's using isset() in the wrong capacity. isset() does not check to see if a variable HAS a value, it checks to see if the variable exists. The variable in the code you posted will always exist, so the use of isset() is redundant and should be changed for something like empty as you noted. Stick the following in the top of your code to see: ?php echo pre; print_r($_GET); echo /pre; ? I feel the book you're learning from might not be the best out there! Especially as it uses the horrible if : else : endif notation, includes code on the same line as the PHP tags themselves and is teaching you to code with register globals on. Is the book still on sale? (i.e. did you buy it recently) or was it something you've had for a while/got 2nd hand? -- Best regards, Richard Davey http://www.phpcommunity.org/wiki/296.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset() question
- Original Message - From: Richard Davey [EMAIL PROTECTED] Hello Anthony, I feel the book you're learning from might not be the best out there! Especially as it uses the horrible if : else : endif notation, includes code on the same line as the PHP tags themselves and is teaching you to code with register globals on. Is the book still on sale? (i.e. did you buy it recently) or was it something you've had for a while/got 2nd hand? Best regards, Richard Davey http://www.phpcommunity.org/wiki/296.html Thank you for the reply Richard. Yes. The book is on sale at: www.sitepoint.com also, at amazon, b and n, etc. In fact, it's now in it's second edition by Kevin Yank. It's not a bad book - quite readable to a newbie like myself - but when I ran that code it didn't jive with that function call. To make sure, I downloaded it from their site and ran it again - and the same thing happened. Thank you for your help. TR --- [This E-mail scanned for viruses by gonefishingguideservice.com] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] isset() question
On Monday 16 February 2004 02:30, Richard Davey wrote: I feel the book you're learning from might not be the best out there! Especially as it uses the horrible if : else : endif notation, includes code on the same line as the PHP tags themselves What is horrible about that style? IMO doing this: ?php if ($something) : ? [... a bunch of HTML ...] ?php endif; ? looks a lot neater than: ?php if ($something) { ? [... a bunch of HTML ...] ?php } ? But whichever style a book chooses to use should not impact on one's decision as to whether it is a good book or not. I have not seen the book in question so I've no idea whether I would find it good or bad. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* There's another way to survive. Mutual trust -- and help. -- Kirk, Day of the Dove, stardate unknown */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] isset bug?
Ok, here's the deal. I like to use $_GET and $_POST variables without values to notify my scripts that some action must be taken. For example, given the following URL: http://blahdomain/blah.php?productid=1edit or given the following form element: input type=hidden name=edit My blah.php script will check if edit set using the following line: if (isset($_REQUEST[edit])) { .. } and then it will take the appropriate actions (lets just say its updating a record in the database). Locally I am running PHPv4.3.2, and everything works fine. I have been working on a large web-based application for the last month, and yesterday I put it up live. Our host unfortunately runs PHPv4.2.1 and I have no access to the conf files (those bastards) and globals are set to on. Low and behold, the isset function returns false when a $_POST or $_GET variable is passed but contains no value, which would be exactly the same thing as checking the variable itself: if ($_REQUEST[edit]) { } What I want and needed to do was check for the existance of the variable, not whether it has a value. So is this a bug, a feature or just some random happening? Thank guys PHP ROCKS -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php