Go Back   Forum Care Forums > Development Reference Area > Php Development

Reply
 
LinkBack Thread Tools Display Modes
Re: [PHP] Function returning but continues execution
Old
  (#1)
David Mytton
Guest
 
Posts: n/a
Default Re: [PHP] Function returning but continues execution - 05-14-2007, 03:36 AM

I added this in and it outputs 1 as I suspected - the function is being
called only once.

David

Robert Cummings wrote:
> On Mon, 2007-01-22 at 16:36 +0000, David Mytton wrote:
>> 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.

>
> A backtrace won't indicate multiple calls unless they are recursive. Try
> add the following to your function:
>
> <?php
>
> static $foo = 0;
> $foo++;
>
> echo "I've been called $foo times\n";
>
> ?>
>
> Cheers,
> Rob.

   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Contact Us - Forum Care Forums - Archive - Top