
ReflectionParameter::canBePassedByValue 메서드는 PHP의 ReflectionParameter 클래스의 메서드입니다. 이 메서드는 매개 변수가 값을 전달할 수 있는지 여부를 확인합니다.
이 메서드는 다음 상황에서 true를 반환합니다.
- 매개 변수가 기본 타입(예: int, string, array 등)일 때
- 매개 변수가 객체의 속성이 아닌 경우
- 매개 변수가 객체의 속성이지만, 객체가 전달할 수 있는 경우 (예: 객체의 속성이 기본 타입일 때)
반면에, 매개 변수가 객체의 속성이고 객체가 전달할 수 없는 경우 (예: 객체의 속성이 객체일 때)에는 false를 반환합니다.
예를 들어, 다음 코드는 매개 변수가 기본 타입일 때 true를 반환합니다.
#hostingforum.kr
php
$reflectionMethod = new ReflectionMethod('Test', 'test');
$reflectionParameter = $reflectionMethod->getParameters()[0];
echo $reflectionParameter->canBePassedByValue() ? 'true' : 'false'; // true
반면에, 다음 코드는 매개 변수가 객체의 속성이므로 false를 반환합니다.
#hostingforum.kr
php
class Test {
public $test;
public function __construct($test) {
$this->test = $test;
}
public function test($test) {
// ...
}
}
$reflectionMethod = new ReflectionMethod('Test', 'test');
$reflectionParameter = $reflectionMethod->getParameters()[0];
echo $reflectionParameter->canBePassedByValue() ? 'true' : 'false'; // false
2025-06-15 05:50