라이브러리
[PHP] ReflectionClass::getNamespaceName - 네임스페이스 이름을 가져옵니다.
ReflectionClass::getNamespaceName
PHP의 ReflectionClass는 클래스의 정보를 가져올 수 있는 클래스입니다. ReflectionClass::getNamespaceName 메소드는 클래스의 네임스페이스를 가져올 수 있습니다.
# 예제
#hostingforum.kr
php
// namespace.php
namespace AppNamespace;
class MyClass {
public function __construct() {
echo "MyClass 생성자 호출
";
}
}
// main.php
require_once 'namespace.php';
$reflectionClass = new ReflectionClass('AppNamespaceMyClass');
echo $reflectionClass->getNamespaceName() . "
"; // AppNamespace
# 설명
* 위 예제에서 `AppNamespaceMyClass` 클래스의 네임스페이스는 `AppNamespace`입니다.
* `ReflectionClass::getNamespaceName` 메소드는 이 네임스페이스를 가져옵니다.
# 사용 방법
* `ReflectionClass` 객체를 생성하여 `getNamespaceName` 메소드를 호출합니다.
* `getNamespaceName` 메소드는 클래스의 네임스페이스를 문자열로 반환합니다.
# 예시 코드
#hostingforum.kr
php
// namespace.php
namespace AppNamespace;
class MyClass {
public function __construct() {
echo "MyClass 생성자 호출
";
}
}
// main.php
require_once 'namespace.php';
$reflectionClass = new ReflectionClass('AppNamespaceMyClass');
echo $reflectionClass->getNamespaceName() . "
"; // AppNamespace
// namespace2.php
namespace AppNamespace2;
class MyClass2 {
public function __construct() {
echo "MyClass2 생성자 호출
";
}
}
// main.php
require_once 'namespace2.php';
$reflectionClass2 = new ReflectionClass('AppNamespace2MyClass2');
echo $reflectionClass2->getNamespaceName() . "
"; // AppNamespace2
# 결론
`ReflectionClass::getNamespaceName` 메소드는 클래스의 네임스페이스를 가져올 수 있습니다. 이 메소드는 클래스의 정보를 가져올 때 유용하게 사용할 수 있습니다.
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.