我知道这并没有确切回答问题,但或许能解释一下背后的动机: 如果你不需要在调用之前进行检查,只是想避免访问其他目录的函数产生警告,另一种方法是使用@运算符并检查error_get_last error_clear_last(); $isDir = @is_dir('/'); if (error_get_last() !== null) { $isDir = 'cannot-detect'; }