gpt4 book ai didi

php - 在 php 中,命名空间是一个正斜杠?

转载 作者:搜寻专家 更新时间:2023-10-31 20:43:04 24 4
gpt4 key购买 nike

为什么命名空间在 PHP 中使用反斜杠 () 来分隔文件夹?

例如:

namespace Core\fruit\Apple;

这有什么特别的原因吗?

我觉得反斜杠约定不合逻辑,因为 unix/linux 文件系统使用正斜杠。但我的意见离题了。

最佳答案

这就是 PHP 决定对 namespace 使用反斜杠的原因:https://wiki.php.net/rfc/namespaceseparator

Criterions
(1) type-ability (how easy is it to type the separator)
(2) typo-vulnerability (how easy is it to make a typo and get an unwanted behavior without a error/warning)
(3) parse-ability (how easy is it to read the code and figure out whats going on without getting confused with similar syntax that means another thing)
(4) IDE compatibility (5) number of chars

一篇表达有趣观点的文章也值得一读:http://www.newmediacampaigns.com/page/php-namespaces-backslash-example

关于php - 在 php 中,命名空间是一个正斜杠?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18095051/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com