2016-11-21 5 views
0

저는 생성자에 정의 된 메서드가있는 nusoap 클래스가 있습니다. 그러나 내가 가지고있는 문제는 내가로드 한 모델 또는 생성자에서 같은 클래스에 정의 된 메서드에서 메서드를 호출하는 것입니다. 내가 얻는 오류는 "객체 컨텍스트에 없을 때 $ this 사용"입니다. 정적 인 메소드는 없으므로 여기에 액세스하는 데 왜 문제가 있는지 잘 모르겠습니다. 참고로 다음은 내가하려는 일의 예입니다.

편집 : 이것은 nusoap으로 작업 한 첫 번째 사례이며, 내가 본 모든 사례의 생성자에서 메서드가 정의되었습니다. 메서드를 생성자에서 정의 할 필요가없는 경우 정의 할 위치는 무엇입니까?

class MySoapServer extends CI_Controller { 
    function __construct() { 
     parent::__construct(); 
     //where I'm loading all my models and libraries, 
     //creating a new instance of soap server 
     //and registering all my methods 


     function myFunction() { 
      $this->testFunction() //this is where it errors out 
     } 
    } 

    function testFunction() { 
     return true; 
    } 
} 

답변

0

함수가 다른 함수에서, 그것은과 같아야합니다

class MySoapServer extends CI_Controller { 
    function __construct() { 
     parent::__construct(); 
     //where I'm loading all my models and libraries, 
     //creating a new instance of soap server 
     //and registering all my methods 


    } 
    function myFunction() { 
     $this->testFunction() //this is where it errors out 
    } 
    function testFunction() { 
     return true; 
    } 
} 

뭘 보인다 생성자 testFunction() 실행을하려고합니다? 그렇다면 myFunction()은 필요하지 않으며 생성자의 끝에 $ this-> testFunction()을 추가하면됩니다. 이처럼

:

class MySoapServer extends CI_Controller { 
     function __construct() { 
      parent::__construct(); 
      //where I'm loading all my models and libraries, 
      //creating a new instance of soap server 
      //and registering all my methods 
      $this->testFunction(); 
     } 
     function testFunction() { 
      return true; 
     } 
    } 
+0

단순함을위한 예제 일 뿐이며, 제 함수는 true를 반환하는 것 이상의 기능을 수행합니다. – Kate

+0

나는 그렇게 생각하지만, 여전히 생성자의 함수를 정당화하지는 못한다. 왜 그렇게 할 필요성을 느끼는지 설명 할 수 있습니까? –

0

나는 nusoap에 대한 전문가가 아니에요하지만 PHP는 매우 잘 중첩 된 함수를 처리하지 않습니다. 왜 당신은 "myFunction"을 생성자 안에 선언하겠습니까? 생성자에서 중첩 함수를 제거해보십시오. 또한 함수의 액세스 한정자를 설정하려고 할 수 있습니다.

+0

내가 생성자에서 사용하는 이유는 sdk에서 매개 변수로 전달 된 자체 함수를 호출해야하기 때문입니다. 만약 내가 그들을 생성자 밖에서 정의한다면, 나는 매개 변수를 제공하지 않고 직접 메서드를 호출해야 할 것이다. – Kate