when to use DIRECTORY_SEPARATOR in PHP code?

前端 未结 3 1108
情话喂你
情话喂你 2020-12-16 11:14

Look at the PHP code:

require_once dirname(__FILE__).DIRECTORY_SEPARATOR . \'./../../../wp-config.php\';
require_once dirname(__FILE__).DIRECTORY_SEPARATOR.\'         


        
3条回答
  •  旧时难觅i
    2020-12-16 12:21

    Because in different OS there is different directory separator. In Windows it's \ in Linux it's /. DIRECTORY_SEPARATOR is constant with that OS directory separator. Use it every time in paths.

    In you code snippet we clearly see bad practice code. If framework/cms are widely used it doesn't mean that it's using best practice code.

提交回复
热议问题