Re: Function returning but continues execution
| From: | David Mytton | Date: | Mon, 22 Jan 2007 16:36:40 +0000 |
| Subject: | Re: Function returning but continues execution | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-247551@lists.php.net to get a copy of this message | ||
Yes, I know it looks like a bug in my code because I'm not able to write a test case that can reproduce it simply enough to report as a bug - hence why I am posting here. However, the behaviour I am describing surely suggests some kind of issue somewhere in PHP itself.
My reasoning for this is if I echo the 2 variables I get:
Array ( [0] => 3 )
and
3
and the bug appears. But if I set them manually before the in_array test:
$_SESSION['user']['friends'] = array(0 => 3);
$friend['user_id'] = 3;
it works as expected. Am I wrong in thinking that this has to be a bug in PHP?
I have used debug_backtrace() to find out what is going on as regards how many times the function is being executed - that is the first thing I checked because it does indeed suggest that it is being executed multiple times, however, the back trace only reveals 1 call/execution.
David
Roman Neuhauser wrote:
# david@emomentum.co.uk / 2007-01-22 15:31:55 +0000:Roman Neuhauser wrote:You have presented no proof that there's a bug in the PHP. What you have presented looks like you have a bug, and the function gets called more than once. Have you used a debugger? See http://xdebug.org/.# david@emomentum.co.uk / 2007-01-22 15:17:16 +0000:I can't see how there is a bug in my code if when I echo the contents of the 2 variables, they are exactly the same as when I set them manually. Except in the former the function "continues executing" but in the latter it doesn't. I also cannot see how the function can return false and execute the SQl query when it is only called once.The key is that the function is returning false but it continues to execute! If I stick in an exit; after the in_array() check at point #4, this doesn't happen. There are no other places where this function is called, and it is only called once. Strangely, if I force the values of the 2 variables before the in_array() check: $_SESSION['user']['friends'] = array(0 => 3); $friend['user_id'] = 3; it reacts as expected - the function returns false and no further code is executed. Anyone have any suggestions?You have a bug somewhere in your code.