여기에 수퍼 단순 스크립트가 있습니다.이 스크립트를 오류없이 실행하고 동일한 작업을 수행하는 방법에 대한 경고가 나오면 계속 변수가 정의되지 않습니다.Public function에서 선언 된 변수는 정의되지 않음을 나타냅니다.
class person{
public $integer=4;
public $name;
public function __construct($name){
$this->name = $name;
}
public function pre(){
return "pre message";
}
public function after($name){
return "post message".$name;
}
};
$person1 = new person($name="jason");
$person2 = new person($name="bourne");
echo $person1->pre();
echo $person2->after();
'$ dog1'과'$ dog2'는 정의되지 않았습니다 ... [좋은 IDE] (http://www.sitepoint.com/best-php-ide-2014-survey-results/)를 사용하여 문제를보십시오 코드를 입력 할 때 코드에서 이러한 문제를 피할 수 있습니다. – DCoder
죄송합니다.이 코드 샘플에서 $ dog1/2를 바꾸는 걸 잊었지만 로컬에서 변경되고 $ person1-> after ($ this-> name)를 추가합니다. 반환 중입니다 치명적인 오류 : – Plentybinary
객체에없는 경우 $ this를 사용하면 정의되지 않은 변수가 함수 후 $ name에 나열됩니다. – Plentybinary