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:
/**
* 連接分布式文件系統(tǒng)
* @access public
* @param string $type 文件類型
* @param array $options 配置數(shù)組
* @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!
業(yè)精于勤,荒于嬉;行成于思,毀于隨。
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.