라이브러리

[PHP] ReflectionClassConstant::getModifiers - 클래스 상수 수정자를 가져옵니다.




ReflectionClassConstant::getModifiers


PHP ReflectionClassConstant::getModifiers 메서드는 클래스 상수에 적용된 모드(Modifiers)를 반환합니다. 모드는 클래스 상수에 적용된 특성(Attributes)입니다.

사용 방법


ReflectionClassConstant::getModifiers 메서드는 ReflectionClassConstant 객체를 반환합니다. ReflectionClassConstant 객체는 클래스 상수에 대한 정보를 제공합니다.

예제


#hostingforum.kr
php

class MyClass {

    const MY_CONSTANT = 10;

    const MY_CONSTANT_2 = 20;

}



$reflectionClass = new ReflectionClass('MyClass');

$reflectionConstant = $reflectionClass->getConstant('MY_CONSTANT');



echo "MY_CONSTANT 모드: " . $reflectionConstant->getModifiers() . "
";

echo "MY_CONSTANT_2 모드: " . $reflectionClass->getConstant('MY_CONSTANT_2')->getModifiers() . "
";



모드 종류


ReflectionClassConstant::getModifiers 메서드는 다음과 같은 모드를 반환할 수 있습니다.

* `ReflectionClassConstant::IS_PUBLIC` : 공개 모드
* `ReflectionClassConstant::IS_PROTECTED` : 보호 모드
* `ReflectionClassConstant::IS_PRIVATE` : private 모드
* `ReflectionClassConstant::IS_STATIC` : 정적 모드
* `ReflectionClassConstant::IS_ABSTRACT` : 추상 모드
* `ReflectionClassConstant::IS_FINAL` : 최종 모드

예제 (모드 종류)


#hostingforum.kr
php

class MyClass {

    public const MY_CONSTANT = 10;

    protected const MY_CONSTANT_2 = 20;

    private const MY_CONSTANT_3 = 30;

    static const MY_CONSTANT_4 = 40;

    abstract const MY_CONSTANT_5 = 50;

    final const MY_CONSTANT_6 = 60;

}



$reflectionClass = new ReflectionClass('MyClass');

$reflectionConstant = $reflectionClass->getConstant('MY_CONSTANT');



echo "MY_CONSTANT 모드: " . $reflectionConstant->getModifiers() . "
";

echo "MY_CONSTANT_2 모드: " . $reflectionClass->getConstant('MY_CONSTANT_2')->getModifiers() . "
";

echo "MY_CONSTANT_3 모드: " . $reflectionClass->getConstant('MY_CONSTANT_3')->getModifiers() . "
";

echo "MY_CONSTANT_4 모드: " . $reflectionClass->getConstant('MY_CONSTANT_4')->getModifiers() . "
";

echo "MY_CONSTANT_5 모드: " . $reflectionClass->getConstant('MY_CONSTANT_5')->getModifiers() . "
";

echo "MY_CONSTANT_6 모드: " . $reflectionClass->getConstant('MY_CONSTANT_6')->getModifiers() . "
";



결론


ReflectionClassConstant::getModifiers 메서드는 클래스 상수에 적용된 모드를 반환합니다. 모드는 클래스 상수에 대한 정보를 제공합니다. PHP Reflection API를 사용하여 클래스 상수에 대한 정보를 얻을 수 있습니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 전체 10,077건 / 287 페이지

검색

게시물 검색