0

クラス内の関数で関数を呼び出すにはどうすればよいですか?

私のコードは次のようになります(例)

    class Test
{

    echo $this->unique();

    public function unique($unique = FALSE)
    {
        function random()
        {
            return 1;
        }

        while($unique === FALSE)
        {
            return $this->random();
            $unique = TRUE;
        }
    }

}

しかし、次のエラーが発生します: Call to undefined method Test::random()

4

3 に答える 3

0

random(); を使用するだけです。

class Test
{

    echo $this->unique();

    public function random()
    {
        return 1;
    }


    public function unique($unique = FALSE)
    {

        while($unique === FALSE)
        {
            return random();
            $unique = TRUE;
        }
    }

}
于 2013-10-25T11:59:55.350 に答える