
ReflectionParameter::__construct 메소드는 PHP ReflectionParameter 클래스의 생성자 메소드입니다. 이 메소드는 ReflectionParameter 객체를 생성하여 PHP 함수나 메소드의 파라미터 정보를 가져올 수 있도록 합니다.
ReflectionParameter::__construct 메소드는 다음과 같은 파라미터를 받을 수 있습니다.
- $class : 파라미터가 있는 클래스 이름
- $name : 파라미터 이름
- $isRef : 파라미터가 참조 타입인지 여부
- $isOptional : 파라미터가 옵션인지 여부
- $isDefaultValueAvailable : 파라미터의 기본값이 있는지 여부
- $defaultValue : 파라미터의 기본값
ReflectionParameter::__construct 메소드를 사용하여 객체를 생성하는 방법은 다음과 같습니다.
#hostingforum.kr
php
$reflectionClass = new ReflectionClass('Person');
$reflectionMethod = $reflectionClass->getMethod('__construct');
$reflectionParameter = $reflectionMethod->getParameters()[0];
$person = new Person();
Person 클래스의 이름, 나이, 주소라는 속성을 초기화하는 방법은 다음과 같습니다.
#hostingforum.kr
php
class Person {
public $name;
public $age;
public $address;
public function __construct($name, $age, $address) {
$this->name = $name;
$this->age = $age;
$this->address = $address;
}
}
$reflectionClass = new ReflectionClass('Person');
$reflectionMethod = $reflectionClass->getMethod('__construct');
$reflectionParameter = $reflectionMethod->getParameters();
$person = new Person();
$person->name = $reflectionParameter[0]->getName();
$person->age = $reflectionParameter[1]->getName();
$person->address = $reflectionParameter[2]->getName();
Person 클래스의 이름, 나이, 주소라는 속성을 초기화하는 예시 코드는 다음과 같습니다.
#hostingforum.kr
php
class Person {
public $name;
public $age;
public $address;
public function __construct($name, $age, $address) {
$this->name = $name;
$this->age = $age;
$this->address = $address;
}
}
$reflectionClass = new ReflectionClass('Person');
$reflectionMethod = $reflectionClass->getMethod('__construct');
$reflectionParameter = $reflectionMethod->getParameters();
$person = new Person();
$person->name = 'John';
$person->age = 30;
$person->address = 'Seoul';
echo $person->name . "n"; // John
echo $person->age . "n"; // 30
echo $person->address . "n"; // Seoul
2025-06-24 05:27