2011-05-05 128 views
0

我使用SimplePhp IRC BOT,您可以在页面上看到所有代码。IRC Php Bot - 嵌套错误

我遇到的问题是主函数调用它递归,所以经过100个电话,它只是错误了,我得到这个错误:

致命错误:“100”最大的功能嵌套层次到达,堕胎!在C:\ XAMPP \ XAMPP \上线htdocs中\联赛\ bot.php 106

我将粘贴下面的一些主要功能:

function main($config) 
    {    
      $data = fgets($this->socket, 256); 

      echo nl2br($data); 

      flush(); 

      $this->ex = explode(' ', $data); 


      if($this->ex[0] == 'PING') 
      { 
        $this->send_data('PONG', $this->ex[1]); //Plays ping-pong with the server to stay connected. 
      } 

      $this->main($config); 
    } 

有没有一种方法来实现相同的功能没有函数调用自己递归?是否可以拥有这种嵌套级别,并且我应该增加嵌套限制xdebug?

回答

3

是 - a while()循环。

无限递归这个变种在PHP中无法有效工作,因为它不会消除尾部调用。虽然您可以增加嵌套限制,但最终会在最终崩溃之前烧毁越来越多的内存。

+0

This Works,thanks! – mike 2011-05-05 19:42:21