라이브러리
[PHP] ReflectionConstant::getExtension - 정의하는 확장의 ReflectionExtension을 가져옵니다.
ReflectionConstant::getExtension
PHP ReflectionClass와 ReflectionMethod, ReflectionFunction, ReflectionProperty와 같은 클래스의 하위 클래스인 ReflectionConstant는 PHP의 Reflection API를 사용하여 클래스의 상수에 대한 정보를 제공합니다.
ReflectionConstant::getExtension 메소드는 클래스의 상수에 대한 정보를 제공하는 ReflectionConstant 객체가 생성된 ReflectionClass의 확장 이름을 반환합니다.
예제
#hostingforum.kr
php
// 예제 클래스
class MyClass {
const MY_CONSTANT = 'Hello, World!';
}
// ReflectionClass 객체 생성
$reflectionClass = new ReflectionClass('MyClass');
// ReflectionConstant 객체 생성
$reflectionConstant = $reflectionClass->getConstant('MY_CONSTANT');
// ReflectionConstant::getExtension 메소드 호출
$extension = $reflectionConstant->getExtension();
// 결과 출력
echo "클래스의 확장 이름: $extension
";
결과
#hostingforum.kr
클래스의 확장 이름: php
설명
위 예제에서, `ReflectionClass` 객체를 생성하여 `MyClass` 클래스에 대한 정보를 얻습니다. 그런 다음, `getConstant` 메소드를 사용하여 `MY_CONSTANT` 상수에 대한 `ReflectionConstant` 객체를 생성합니다.
`ReflectionConstant::getExtension` 메소드를 호출하여 클래스의 확장 이름을 얻은 후, 결과를 출력합니다.
참고
- PHP Reflection API: https://www.php.net/manual/en/book.reflection.php
- ReflectionClass: https://www.php.net/manual/en/class.reflectionclass.php
- ReflectionConstant: https://www.php.net/manual/en/class.reflectionconstant.php
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.