鍍金池/ 問(wèn)答/PHP/ PHP file_exists()函數(shù)前加反斜杠“\”是什么意思?

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

在查看phpunit代碼看是如何加載phpunit的配置文件的,發(fā)下在調(diào)用 file_exsits()函數(shù)時(shí)在前面加了一個(gè)反斜杠“\”,代碼如下:

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')) 這個(gè)時(shí)什么意思?能到指定從根目錄查找“phpunit.xml”文件嗎?;

回答
編輯回答
萌小萌

PHP在表示命名空間的時(shí)候會(huì)用到反斜杠,此處的單個(gè)反斜杠就是表示在當(dāng)前命名空間內(nèi)調(diào)用全局的方法,具體可以看看命名空間相關(guān)資料。
file_exists(path)
這是用法,就是在指定路徑查找文件是否存在。

2018年2月15日 17:31