
DocResult::__construct 메소드는 PHP의 클래스 인스턴스를 초기화하는 데 사용됩니다. 이 메소드는 클래스의 속성을 초기화하고, 객체를 생성하는 역할을 합니다.
이 메소드의 파라미터는 클래스의 속성을 초기화하기 위해 필요한 값들입니다. 예를 들어, 이름, 아이디, 비밀번호 등이 포함될 수 있습니다.
반환값은 객체 인스턴스 자체입니다. 이 메소드는 객체를 생성하고 초기화하여 반환합니다.
예시 코드는 다음과 같습니다.
#hostingforum.kr
php
class DocResult {
private $name;
private $id;
private $password;
public function __construct($name, $id, $password) {
$this->name = $name;
$this->id = $id;
$this->password = $password;
}
public function getName() {
return $this->name;
}
public function getId() {
return $this->id;
}
public function getPassword() {
return $this->password;
}
}
$docResult = new DocResult('John Doe', 'john', 'password123');
echo $docResult->getName(); // John Doe
echo $docResult->getId(); // john
echo $docResult->getPassword(); // password123
이 예시 코드에서 `DocResult::__construct` 메소드는 `DocResult` 클래스의 속성을 초기화합니다. `new` 키워드를 사용하여 객체 인스턴스를 생성하고, `__construct` 메소드를 호출하여 객체를 초기화합니다.
2025-08-12 11:01