
SplFileInfo::getPath() 함수의 반환 값은 string 타입이 아닐 수도 있습니다. 이 경우에는 다음과 같이 처리할 수 있습니다.
#hostingforum.kr
php
$filePath = '/path/to/your/file.txt';
$fileInfo = new SplFileInfo($filePath);
$dirPath = $fileInfo->getPath();
if (is_string($dirPath)) {
// string 타입인 경우
var_dump($dirPath);
} elseif (is_dir($dirPath)) {
// 디렉토리 타입인 경우
var_dump($dirPath);
} else {
// 다른 타입인 경우
var_dump('unknown type');
}
또는, SplFileInfo::getPath() 함수의 반환 값을 string 타입으로 강제로 변환할 수도 있습니다.
#hostingforum.kr
php
$filePath = '/path/to/your/file.txt';
$fileInfo = new SplFileInfo($filePath);
$dirPath = (string)$fileInfo->getPath();
var_dump($dirPath);
이 경우에는 SplFileInfo::getPath() 함수가 string 타입을 반환하지 않는 경우, PHP가 자동으로 string 타입으로 변환하도록 합니다.
2025-04-26 08:55