라이브러리

[PHP] ReflectionClass::getMethods - 메서드 배열을 가져옵니다.




ReflectionClass::getMethods


PHP의 ReflectionClass는 클래스의 정보를 가져올 수 있는 클래스입니다. ReflectionClass::getMethods 메서드는 클래스의 메서드 정보를 가져올 수 있는 메서드입니다.

# 사용법


ReflectionClass::getMethods 메서드는 다음과 같이 사용할 수 있습니다.

#hostingforum.kr
php

$reflectionClass = new ReflectionClass('클래스 이름');

$methods = $reflectionClass->getMethods();



# 예제


다음 예제는 ReflectionClass::getMethods 메서드를 사용하여 클래스의 메서드 정보를 가져오는 방법을 보여줍니다.

#hostingforum.kr
php

class MyClass {

    public function myMethod1() {

        echo "myMethod1 호출
";

    }



    protected function myMethod2() {

        echo "myMethod2 호출
";

    }



    private function myMethod3() {

        echo "myMethod3 호출
";

    }

}



$reflectionClass = new ReflectionClass('MyClass');

$methods = $reflectionClass->getMethods();



foreach ($methods as $method) {

    echo "메서드 이름: " . $method->getName() . "
";

    echo "접근 수준: " . $method->isPublic() ? 'public' : ($method->isProtected() ? 'protected' : 'private') . "
";

    echo "정적 메서드: " . $method->isStatic() ? 'true' : 'false' . "
";

    echo "------------------------------------------------
";

}



# 결과


이 예제를 실행하면 다음과 같은 결과가 나옵니다.

#hostingforum.kr


메서드 이름: myMethod1

접근 수준: public

정적 메서드: false

------------------------------------------------

메서드 이름: myMethod2

접근 수준: protected

정적 메서드: false

------------------------------------------------

메서드 이름: myMethod3

접근 수준: private

정적 메서드: false

------------------------------------------------



# 메서드 정보


ReflectionClass::getMethods 메서드는 ReflectionMethod 객체의 배열을 반환합니다. 이 객체에는 메서드의 정보가 포함되어 있습니다.

* `getName()`: 메서드 이름을 반환합니다.
* `isPublic()`, `isProtected()`, `isPrivate()`: 메서드의 접근 수준을 반환합니다.
* `isStatic()`: 메서드가 정적 메서드인지 여부를 반환합니다.

# 참고


ReflectionClass::getMethods 메서드는 클래스의 메서드 정보를 가져올 수 있는 메서드입니다. 이 메서드를 사용하여 클래스의 메서드 정보를 가져올 수 있습니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

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

검색

게시물 검색