
ReflectionParameter::export를 사용하여 클래스의 속성을 Export할 때, 속성의 이름이 변경되는 이유는 PHP의 네이밍 컨벤션 때문입니다. PHP는 underscore를 사용하여 카멜케이스 이름을 언더스코어로 변환하는 규칙을 따릅니다.
예를 들어, `myProperty`는 `my_property`로 변환됩니다.
속성이 Export될 때 원래 이름을 유지하려면, 네이밍 컨벤션을 따르는 대신에, `ReflectionParameter::export`에 옵션을 추가하여 이름을 변경하지 않도록 할 수 있습니다.
#hostingforum.kr
php
use ReflectionClass;
use ReflectionProperty;
$reflectionClass = new ReflectionClass('MyClass');
$reflectionProperty = $reflectionClass->getProperty('myProperty');
$exportedName = $reflectionProperty->getName(); // myProperty
$exportedName = str_replace('_', '', $exportedName); // myProperty
또는, `ReflectionParameter::export` 옵션을 사용하여 이름을 변경하지 않도록 할 수 있습니다.
#hostingforum.kr
php
use ReflectionClass;
use ReflectionProperty;
$reflectionClass = new ReflectionClass('MyClass');
$reflectionProperty = $reflectionClass->getProperty('myProperty');
$exportedName = $reflectionProperty->getName(); // myProperty
$exportedName = str_replace('_', '', $exportedName); // myProperty
// 옵션을 사용하여 이름을 변경하지 않도록 함
$reflectionProperty->setExportName($exportedName);
이러한 방법으로, 속성이 Export될 때 원래 이름을 유지할 수 있습니다.
2025-03-13 11:05