donglong9745 2010-05-23 18:03
浏览 33
已采纳

如何在PHP OOP中访问函数

What do I need to do to call $this->two() from inside my function innerOne? Is that possible with PHP OOP?

Here's the error I am recieving:

Fatal error: Using $this when not in object context

Here's how my code looks:

class myClass  {

    function one(){

        function innerOne() {
            // Some code
            $this->two($var1, $var2);
        }

        // Some code

        innerOne();

    }

    function two($var1, $var2) {
    // Does magic with passed variables
        return $var1 . $var2;
    }


}
  • 写回答

3条回答 默认 最新

  • dsjgk330337 2010-05-23 18:04
    关注

    Try this:

    function innerOne($t) {
      //some code...
      $t->two($var1, $var2);
    }
    
    innerOne($this);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?