2010-12-23 5 views
6

나는이 오류 얻을 왜 어떤 생각이 코드경고 : 누락 한 인수

Warning: Missing argument 1 for person::__construct(), called in /home/fishbein/public_html/dev/OOP/index.php on line 5 and defined in /home/fishbein/public_html/dev/OOP/class_lib.php on line 6 

Warning: Missing argument 1 for person::__construct(), called in /home/fishbein/public_html/dev/OOP/index.php on line 6 and defined in /home/fishbein/public_html/dev/OOP/class_lib.php on line 6 

을 :

$tyler = new person("Tyler"); 
: 나는 또한 내 인덱스 파일이 사용하고

<? 
    class person { 

      var $name; 

      function __construct($persons_name) {  
      $this->name = $persons_name;   
      } 

      function set_name($new_name) { 
       $this->name = $new_name; 
      } 

      function get_name() { 
       return $this->name; 
      } 

    } 
?> 

+3

index.php에 5 행과 6 행을 게시해야합니다. 그것이 바로 버그입니다. – Chris

답변

11

같은 일을하고있다 : $obj = new person(); 대신이 같은 설정을

+1

그러나 나는 $ tyler = 새로운 사람 ("타일러")을 사용하고 있습니다. – Phil

+0

$ tyler = 새 사람; $ tyler :: set_name ("타일러"); ... 구조를 제거하고 이와 같이 시도하십시오. –

+6

클래스에서 do 함수 __construct ($ persons_name = "")를 수행합니다. – Babiker

2

인수를 전달하지 않고 생성자를 호출하고 있습니다. 당신이 한 인스턴스화 할 때 아마 당신은 $p = new person(); 대신 $p = new person("theirName");

+0

@Phil : Brian의 대답이 끝났습니다. $ p = new Person ("theirName"); \ –

+0

$ tyler = 새로운 사람 ("타일러"); – Phil

4
$persons_name = "" 

$obj = new person("joe");의 인수. 그러나 그것은 해결책이 아닙니다. 생성물을 제거하고 새 인스턴스를 만든 다음 이름을 설정할 수 있습니다. 네가 어떻게 든 작동하지 않으면.

+0

__construct() 설명 +1. __construct ($ persons_name = "")가 정확합니다. – jhamPac

0

것 같습니다 : 클래스 이름이 함수 이름과 같으면이 경고가 제공됩니다. 함수의 이름을 클래스 이름과 다르게하면 괜찮은 것 같습니다. 그 클래스의 인스턴스

0

에없는 기능을 호출 할 때이 코드를 구조 방법 내부

function __construct($persons_name= NULL) {  
      $this->name = $persons_name;   
      } 

초기화 NULL을 시도만을 인수를 제공해야합니다.