PHP file_exists()函数前加反斜杠“\”是什么意思?

在查看phpunit代码看是如何加载phpunit的配置文件的,发下在调用 file_exsits()函数时在前面加了一个反斜杠“\”,代码如下:

if (isset($this->arguments['configuration']) &&
            \is_dir($this->arguments['configuration'])) {
            $configurationFile = $this->arguments['configuration'] . '/phpunit.xml';

            if (\file_exists($configurationFile)) {
                $this->arguments['configuration'] = \realpath(
                    $configurationFile
                );
            } elseif (\file_exists($configurationFile . '.dist')) {
                $this->arguments['configuration'] = \realpath(
                    $configurationFile . '.dist'
                );
            }
        } elseif (!isset($this->arguments['configuration']) &&
            $this->arguments['useDefaultConfiguration']) {
            if (\file_exists('phpunit.xml')) {
                $this->arguments['configuration'] = \realpath('phpunit.xml');
            } elseif (\file_exists('phpunit.xml.dist')) {
                $this->arguments['configuration'] = \realpath(
                    'phpunit.xml.dist'
                );
            }
        }

if (\file_exists('phpunit.xml')) 这个时什么意思?能到指定从根目录查找“phpunit.xml”文件吗?;

叮当猫咪
浏览 788回答 1
1回答

绝地无双

PHP在表示命名空间的时候会用到反斜杠,此处的单个反斜杠就是表示在当前命名空间内调用全局的方法,具体可以看看命名空间相关资料。file_exists(path)这是用法,就是在指定路径查找文件是否存在。
打开App,查看更多内容
随时随地看视频慕课网APP