开发者

Function always return null

I'm not sure why, but I've created a function and somehow it never return anything. It supposed to return a random number generated by using the mt_rand() function. I modified the code and tried to run it on ideone and the results says runtime error, signal 11 (SIGSEGV)

Can someone tell me what's wrong with this?

<?php
    function breedingTree($name, $N, $max) 
    {
        include('config.php');
        if ($N < $max AND $name > 0) 
        开发者_如何学JAVA{

            $sql = 'SELECT sire, dam
                    FROM '.$prefix.'owned_adoptables
                    WHERE aid = "'.$name.'"';
            $res = mysql_query($sql);
            list($s, $d) = mysql_fetch_row($res);
            if (mt_rand(0,1) === 1) breedingTree($s, $N+1, $max);
            else breedingTree($d, $N+1, $max);

        }
        elseif ($name <= 0)
        {

            if ($N === 0) return mt_rand(1,100);
            elseif ($N === 1) return mt_rand(5,95);
            elseif ($N === 2) return mt_rand(15,85);
            elseif ($N === 3) return mt_rand(25,75);

        }

    }

echo breedingTree(355, 0, 4); // Return nothing
echo breedingTree(0, 0, 4); // Return random number between 1 - 100
?>


What if $N is not 0, 1, 2, or 3, or if ($N < $max AND $name > 0), or if ($N >= max AND $name > 0)? There is no return statement for those code paths.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜