thinkphp - What is the difference between "\" and "\\" when splicing paths in php?
迷茫
迷茫 2017-05-31 10:33:52
0
1
845

I looked at the source code of thinkphp3.2 today and found that the connect method in Thinkphp/Library/Think/Storage.class.php is a bit confusing. The code is:

/**
 * 连接分布式文件系统
 * @access public
 * @param string $type 文件类型
 * @param array $options  配置数组
 * @return void
 */
static public function connect($type='File',$options=array()) {
    $class  =   'Think\Storage\Driver\'.ucwords($type);
    self::$handler = new $class($options);
}

Why does the path in $class need "\\" instead of "\\"? The last "\\" is to convert "'" single quotes, which is understandable, but the first two "\\" are not That's very understandable, because in my memory it seems that it is possible to use "\" directly, and here, no error is reported when changing "\\" to "\". I think it may be for some better or safer considerations. , or for use in __autoload() later, but specifically why "\\" should be written, I hope any brother knows, let me know, thank you!

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(1)
巴扎黑

Simply put, it is more rigorous to use \ to avoid problems that may arise when using alone. In actual production, as long as there is no escaping problem, the specific writing is the same, but the premise is that you are very sure of your code. If you are not sure, writing \ is a more reliable solution.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!