是否需要使用目录分隔符常量? [英] Is using the directory separator constant necessary?

查看:90
本文介绍了是否需要使用目录分隔符常量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PHP,但是我这个问题可能与语言无关.

对于PHP,常量由PHP定义,称为DIRECTORY_SEPARATOR.我已经在Joomla中看到了

define('DS', DIRECTORY_SEPARATOR);

我认为这似乎是个好主意,因此将其合并到我的一些网站中.现在我问自己为什么.我只有Windows和OS X的经验,据我所知,Microsoft,Linux和Apple都使用正斜杠作为目录分隔符.

使用此常量是否不必要?

解决方案

例如,Mac OS Classic使用:".有关详细信息,请参见 Wikipedia .避免使用魔术数字"或类似的构造也被认为是很好的样式.

I am using PHP, but I guess this question might be language agnostic.

With PHP, a constant is defined by PHP, called DIRECTORY_SEPARATOR. I have seen this in Joomla

define('DS', DIRECTORY_SEPARATOR);

I thought this looked like a good idea so I incorporated it into some of my sites. Now I'm asking myself why. I have only experience on Windows and OS X and from what I know Microsoft, Linux and Apple all use the forward slash as the directory separator.

Is using this constant unnecessary?

解决方案

Mac OS Classic uses ":", for instance. See Wikipedia for details. Also it's considered good style avoiding 'magic numbers' or similar constructs.

这篇关于是否需要使用目录分隔符常量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆