简体   繁体   中英

In php, namespaces a forward slash?

Why do namespaces, in PHP, use a backslash () to seperate folders?

Eg:

namespace Core\fruit\Apple;

Are there any particular reasons for this?

I feel the backslash convention is illogical because unix/linux file systems utilize forward slashes. But my opinion is beside the point.

Here's why PHP decided to use backslash for namespaces: 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

An article expressing an interesting opinion is a good read also: http://www.newmediacampaigns.com/page/php-namespaces-backslash-example

Totally silly choice... On AZERTY keyboards \ is one of the most difficult key to type. / or. are

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM