btherl Posted December 17, 2006 Share Posted December 17, 2006 I have a very odd situation occurring in my code. The entire app is around 50k LOC and uses postgres.The situation only occurs when processing large amounts of data.The code with unusual behaviour looks like this:[code=php:0]if($_REQUEST['exceltype'] == 'yes'){[/code]Now, $_REQUEST['exceltype'] is not set, as verified by var_dump($_REQUEST) inside this if statement. BUT, the if statement succeeds! The if statement fails if I use === instead of ==.Is there any setting or circumstance in php which could cause unset values to evaluate as equal (in the == sense) to a string?More information: The code is running on the following system:Server: Apache/1.3.33 (Debian GNU/Linux) mod_gzip/1.3.26.1a PHP/4.3.10-18 mod_auth_pam/1.1.1 mod_ssl/2.8.22 OpenSSL/0.9.7e mod_perl/1.29 mod_choke/0.06 Link to comment https://forums.phpfreaks.com/topic/30935-solved-in-what-circumstances-does-unset-var-string/ Share on other sites More sharing options...
corbin Posted December 17, 2006 Share Posted December 17, 2006 The only way that statement should work is if $_POST['exceltype'], $_GET['exceltype'], or $_COOKIE['exceltype'] are set to yes... Link to comment https://forums.phpfreaks.com/topic/30935-solved-in-what-circumstances-does-unset-var-string/#findComment-142727 Share on other sites More sharing options...
btherl Posted December 17, 2006 Author Share Posted December 17, 2006 Corbin, the point of my post is that they are not set to 'yes', but the expressions are still evaluating to true. In fact, they are not set to any value.If anyone can explain how this could happen, I am very interested to hear :) Link to comment https://forums.phpfreaks.com/topic/30935-solved-in-what-circumstances-does-unset-var-string/#findComment-142733 Share on other sites More sharing options...
kenrbnsn Posted December 17, 2006 Share Posted December 17, 2006 You only want to do the comparison if it is set, so change the "if" to:[code]<?phpif(isset($_REQUEST['exceltype'] && $_REQUEST['exceltype'] == 'yes'){?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/30935-solved-in-what-circumstances-does-unset-var-string/#findComment-142734 Share on other sites More sharing options...
btherl Posted December 17, 2006 Author Share Posted December 17, 2006 I understand what you are saying Ken, but it doesn't answer my question. It's not necessary to test for setness before making a comparison with == under usual circumstances, as null != 'yes'.Try the following test script[code=php:0]<?phpif ($a == 'yes') print "Unset variable is == to string constant\n";?>[/code] Link to comment https://forums.phpfreaks.com/topic/30935-solved-in-what-circumstances-does-unset-var-string/#findComment-142737 Share on other sites More sharing options...
corbin Posted December 17, 2006 Share Posted December 17, 2006 Yeah so ummmm[code=php:0]<?if($_REQUEST['exceltype'] == 'yes'){echo "yes";}else {echo "no";}?>[/code]Returns no for me... Link to comment https://forums.phpfreaks.com/topic/30935-solved-in-what-circumstances-does-unset-var-string/#findComment-142741 Share on other sites More sharing options...
kenrbnsn Posted December 17, 2006 Share Posted December 17, 2006 I tried your example and got the expected results, i.e. nothing printed. I also tried:[code]<?php$a = array();if ($a['x'] == 'yes') print "Unset variable is == to string constant\n";if ($_REQUEST['x'] == 'yes') print "Unset variable is == to string constant\n";?>[/code]And neither "if" resulted in anything being printed.What is your configuration?Ken Link to comment https://forums.phpfreaks.com/topic/30935-solved-in-what-circumstances-does-unset-var-string/#findComment-142742 Share on other sites More sharing options...
btherl Posted December 17, 2006 Author Share Posted December 17, 2006 Here's what I'm using:Server: Apache/1.3.33 (Debian GNU/Linux) mod_gzip/1.3.26.1a PHP/4.3.10-18 mod_auth_pam/1.1.1 mod_ssl/2.8.22 OpenSSL/0.9.7e mod_perl/1.29 mod_choke/0.06I suspect I've found an obscure bug in php 4.3.10 .. I guess it's time to upgrade :)The test script returns the expected results for me too. It's only the application when running on certain data sets that results in the strange behaviour.I've sat and stared at the output for quite some time, but no luck.. the if condition succeeds, but when I var_dump($_REQUEST) INSIDE the if, the tested array entry is not there. I tried a few others, like [code=php:0]if ($_REQUEST['bubbles'] == 'bubbly')[/code] and they succeeded too. All tests with === failed as expected, such as [code=php:0]if ($_REQUEST['bubbles'] === 'bubbly')[/code].Thanks for your help guys :) I'm going to file this under 'unreproducible bugs' (I found some others related to large arrays causing seg faults too, all fixed in php 5) Link to comment https://forums.phpfreaks.com/topic/30935-solved-in-what-circumstances-does-unset-var-string/#findComment-142750 Share on other sites More sharing options...
trq Posted December 17, 2006 Share Posted December 17, 2006 Nothing to do with your problem, but just some clarification.[quote]It's not necessary to test for setness before making a comparison with == under usual circumstances[/quote]Yes it is. Otherwise if you try and do a comparison on a variable that isn't set you generate a notice. Link to comment https://forums.phpfreaks.com/topic/30935-solved-in-what-circumstances-does-unset-var-string/#findComment-142751 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.