Re: Function returning but continues execution

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Please don't top post and trim the quoted material if you want me to
discuss this with you.

# david@xxxxxxxxxxxxxxx / 2007-01-22 16:36:40 +0000:
> Roman Neuhauser wrote:
> ># david@xxxxxxxxxxxxxxx / 2007-01-22 15:31:55 +0000:
> >>I also cannot see how the function can return false and execute the SQl 
> >>query when it is only called once.
> >
> >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/.
> 
> 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 - 

Write tests that prove the code does what you think it does. Which of
these tests will break?

> However, the behaviour I am describing surely suggests some kind of
> issue somewhere in PHP itself.

I still have no reason to believe it.  Such a bug in PHP would require
memory corruption in the Zend engine.  I run complex code in 5.2 on Linux,
and haven't seen anything like that.

> 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?

You haven't shown the complete code, and what you *have* shown didn't
prove anything. Show me that it really gets past the return. var_dump() the
two things your comparing there with in_array() *after* the if() block,
and prove that it's in the same invocation as that return false.

function f()
{
    static $x = 0;
    $i++;
    if (!in_array($friend, $friends)) {
        var_dump("inside", $i, $friend, $friends);
        return false;
    }
    var_dump("after", $i, $friend, $friends);
    $core->database->exec(...);
}

> 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.

Not suprprising. This code outputs

#0  f(1) called at [/usr/home/roman/tmp/scratch30:8]
#0  f(2) called at [/usr/home/roman/tmp/scratch30:8]

<?php

function f($i)
{
    debug_print_backtrace();
}
foreach (range(1, 2) as $i) {
    f($i);
}


-- 
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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux