可以~但是你上面的写法有点问题。
class Lei { 
  function set() { 
      $a =2; 
      return $a;
    } 
  function add(){ 
$lei = new Lei(); 
$a = $lei->set(); 
echo 1+$a; 
  } 
}
$a = new Lei();
echo $a->add();

解决方案 »

  1.   

    <?php 
    class Lei 

        var $a; 
        function set($n) 
        { 
            $this->a = $n; 
        } 
        function show() 
        { 
            return $this->a; 
        } 
    } $lei = new Lei();
    $lei->set(2);
    echo $lei->show(); 
    ?> 
      

  2.   

    为什么这么调?在类内部调用本类方法,应该用$this,你为什么在类内部要将它实例化了?
      

  3.   

    class Lei {
      function set() {
          $this->a =2;
        }
      function add(){
    self::set();
    echo 1+$this->a;
      }
    }$test = new Lei();
    $test->add();