라이브러리
[PHP] ReflectionFunctionAbstract::getFileName - 파일 이름을 가져옵니다.
ReflectionFunctionAbstract::getFileName()
`ReflectionFunctionAbstract::getFileName()` 메소드는 함수가 정의된 파일의 이름을 반환합니다. 이 메소드는 `ReflectionFunction` 클래스의 상속된 메소드이므로, `ReflectionFunction` 클래스의 인스턴스를 생성할 때 사용할 수 있습니다.
예제
#hostingforum.kr
php
// test.php 파일에 다음 코드를 추가합니다.
function testFunction() {
echo "Hello, World!";
}
// index.php 파일에서 다음 코드를 추가합니다.
require_once 'test.php';
$reflection = new ReflectionFunction('testFunction');
echo $reflection->getFileName(); // test.php
위의 예제에서 `testFunction` 함수는 `test.php` 파일에 정의되어 있습니다. `index.php` 파일에서 `ReflectionFunction` 클래스의 인스턴스를 생성하고 `getFileName()` 메소드를 호출하여 함수가 정의된 파일의 이름을 출력합니다.
추가 예제
#hostingforum.kr
php
// test.php 파일에 다음 코드를 추가합니다.
function testFunction() {
echo "Hello, World!";
}
function testFunction2() {
echo "Hello, World! 2";
}
// index.php 파일에서 다음 코드를 추가합니다.
require_once 'test.php';
$reflection1 = new ReflectionFunction('testFunction');
$reflection2 = new ReflectionFunction('testFunction2');
echo $reflection1->getFileName() . "
"; // test.php
echo $reflection2->getFileName() . "
"; // test.php
위의 예제에서 두 개의 함수가 `test.php` 파일에 정의되어 있습니다. `index.php` 파일에서 `ReflectionFunction` 클래스의 인스턴스를 생성하고 `getFileName()` 메소드를 호출하여 함수가 정의된 파일의 이름을 출력합니다. 두 함수 모두 동일한 파일에 정의되어 있기 때문에 동일한 파일 이름이 출력됩니다.
주의
`getFileName()` 메소드는 함수가 정의된 파일의 이름을 반환합니다. 함수가 포함된 파일이 변경되거나 함수가 다른 파일로 이동되면 `getFileName()` 메소드의 반환값이 변경됩니다.
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.