Php namespaces why backslash
Reasons and two possible solutions described in the ZendOptimizerPlus issue. On its own, that does nothing at all it's not valid syntax. However, if you have something like this:. You will see Hello world! What does a backslash do in PHP 5. Asked 6 Months ago Answers: 5 Viewed 29 times. What does a do in PHP? If I don't use namespaces, should I care about any of this? How do I use internal or global classes in a namespace? How do I use namespaces classes functions, or constants in their own namespace?
How does an unqualified class name like name resolve? How does an unqualified function name or unqualified constant name like name resolve? There are a few implementation details of the namespace implementations that are helpful to understand. Import names cannot conflict with classes defined in the same file. Nested namespaces are not allowed. Before PHP 5. It's a hack solution. Gavin - you would not call a function in a namespace like that.
AlmostAlive - The internals team tried :: and implemented it in earlier releases of 5. I have a hard time believing if it could have been made to work without tremendous downside and a breaking of backwards compatibility with the existing :: operator they would have gone that road and not reimplemented with a new operator. So pressing that key is a deliberate action to qualify a name space.
I can see where Windows users might be a little more annoyed. You missed the only valid argument: PHP already has a namespace operator! Instead, because nobody wanted to fix the bunged up internals to make it work properly, they decided to add this new character and make the whole language that much more complicated. Now we have this new operator that we didn't need and a bunch of different syntax and semantics for accessing static class members and namespaces. On PHP 5. July 31, Prior to native namespace support frameworks and libraries could optimize for either: Simple class names, at cost of higher collision potential.
Few class name collisions, at cost of convoluted class names. In retrospect the circus of negativity around the new namespaces boiled down to three things: As programmers and language lovers it's really easy to get drawn into a heated bikeshed debate on something as trivial as the character a language chooses for delimiting a new token in their programming language.
It's easy to dismiss PHP's every move as a programming language. What's hard to appreciate is that PHP is the most widely used dynamic language that exists. The internals team carries the weight of knowing when they change the PHP language it has wider-ranging impact than every other dynamic language.
The internals team dropped the ball when communicating the change with the outside world. Active Oldest Votes. Improve this answer. Yeah, escaping the backslash is not strictly necessary in this case, but it really can't hurt to. Howard Updated my answer to touch on that subject in particular. Aalawlx Aalawlx 4 4 silver badges 23 23 bronze badges. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password.
Post as a guest Name. Email Required, but never shown. The Overflow Blog.
0コメント