라이브러리

[PHP] ReflectionConstant::getShortName - 짧은 이름을 가져옵니다.




ReflectionConstant::getShortName


PHP ReflectionConstant 클래스의 `getShortName` 메서드는 상수 이름을 반환합니다. 이 메서드는 ReflectionClass 또는 ReflectionProperty 인스턴스에 대해 호출할 수 있으며, 상수 이름을 반환합니다.

사용법


`getShortName` 메서드는 다음과 같이 사용할 수 있습니다.

#hostingforum.kr
php

use ReflectionClass;



$reflectionClass = new ReflectionClass('MyClass');

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



$shortName = $constant->getShortName();

echo $shortName; // MY



예제


다음 예제에서는 ReflectionClass와 ReflectionConstant을 사용하여 상수 이름을 가져오는 방법을 보여줍니다.

#hostingforum.kr
php

use ReflectionClass;

use ReflectionConstant;



class MyClass {

    const MY_CONSTANT = 'MY_VALUE';

}



$reflectionClass = new ReflectionClass('MyClass');

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



$shortName = $constant->getShortName();

echo $shortName; // MY



$propertyName = $constant->getName();

echo $propertyName; // MY_CONSTANT



$propertyValue = $constant->getValue();

echo $propertyValue; // MY_VALUE



참고


* ReflectionClass: PHP ReflectionClass 클래스를 사용하여 클래스 정보를 가져올 수 있습니다.
* ReflectionConstant: PHP ReflectionConstant 클래스를 사용하여 상수 정보를 가져올 수 있습니다.
* getConstant: ReflectionClass 인스턴스에 대해 호출하여 상수 이름과 값을 가져올 수 있습니다.
* getName: ReflectionConstant 인스턴스에 대해 호출하여 상수 이름을 가져올 수 있습니다.
* getValue: ReflectionConstant 인스턴스에 대해 호출하여 상수 값을 가져올 수 있습니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

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

검색

게시물 검색