TomTees Posted November 8, 2010 Share Posted November 8, 2010 Does the concept of a "Namespace" exist in PHP? If so, how do you use them? This is a snippet from ASP.NET that made me ask this question... <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.SqlClient" %> TomTees Quote Link to comment https://forums.phpfreaks.com/topic/218069-do-namespaces-exist-in-php/ Share on other sites More sharing options...
revraz Posted November 8, 2010 Share Posted November 8, 2010 Namespaces are a .net concept. With that said, I guess you could use includes to try and get the same result. Quote Link to comment https://forums.phpfreaks.com/topic/218069-do-namespaces-exist-in-php/#findComment-1131623 Share on other sites More sharing options...
TomTees Posted November 8, 2010 Author Share Posted November 8, 2010 Namespaces are a .net concept. With that said, I guess you could use includes to try and get the same result. Namespaces may not be a PHP concept, but they are certainly not just limited to .Net so I wouldn't say "they are a .Net concept". (Maybe you were just saying that in context?) I believe they are used also in C, C++, Java, and so on. TomTees Quote Link to comment https://forums.phpfreaks.com/topic/218069-do-namespaces-exist-in-php/#findComment-1131634 Share on other sites More sharing options...
trq Posted November 8, 2010 Share Posted November 8, 2010 namespaces exist in php since 5.3 http://php.net/namespaces Quote Link to comment https://forums.phpfreaks.com/topic/218069-do-namespaces-exist-in-php/#findComment-1131635 Share on other sites More sharing options...
KevinM1 Posted November 8, 2010 Share Posted November 8, 2010 ...and the syntax is ugly as sin. Quote Link to comment https://forums.phpfreaks.com/topic/218069-do-namespaces-exist-in-php/#findComment-1131667 Share on other sites More sharing options...
trq Posted November 8, 2010 Share Posted November 8, 2010 ...and the syntax is ugly as sin. It works though. Quote Link to comment https://forums.phpfreaks.com/topic/218069-do-namespaces-exist-in-php/#findComment-1131669 Share on other sites More sharing options...
KevinM1 Posted November 8, 2010 Share Posted November 8, 2010 ...and the syntax is ugly as sin. It works though. True. I just greatly prefer the dot syntax used by the other big players. Quote Link to comment https://forums.phpfreaks.com/topic/218069-do-namespaces-exist-in-php/#findComment-1131673 Share on other sites More sharing options...
trq Posted November 8, 2010 Share Posted November 8, 2010 Yeah, pretty well impossible considering its already the concat operator though. Quote Link to comment https://forums.phpfreaks.com/topic/218069-do-namespaces-exist-in-php/#findComment-1131677 Share on other sites More sharing options...
salathe Posted November 8, 2010 Share Posted November 8, 2010 Thorpe, it would be entirely possible. However, the changes to the language, and performance impact of such changes, would make using the dot operator out of the question. Good luck trying to work out whether the aim is to concatenate constants or use some namespaced item! Nightslyr, if your main problem is the syntax being "ugly" then I'd say that's a big win for the implementation! Personally, I quite like the backslash as namespace separator. TomTees, as thorpe pointed out, you can use namespaces as of PHP 5.3.0 much like you would with your example in the first post. The keyword to look for, rather than import is use. Quote Link to comment https://forums.phpfreaks.com/topic/218069-do-namespaces-exist-in-php/#findComment-1131726 Share on other sites More sharing options...
KevinM1 Posted November 8, 2010 Share Posted November 8, 2010 How much of a performance impact would it be if PHP used an overload of + as its string concatenation operator? Quote Link to comment https://forums.phpfreaks.com/topic/218069-do-namespaces-exist-in-php/#findComment-1131769 Share on other sites More sharing options...
Anti-Moronic Posted November 8, 2010 Share Posted November 8, 2010 Noticed a LOT of small questions regarding different parts of more advanced PHP from Tom - might I advise you buy yourself a few decent books and read them. You can get the answer to this question within 10 seconds if you search google. Here's a link to another thread regarding good PHP books: http://www.phpfreaks.com/forums/miscellaneous/good-programming-and-web-design-books/ Hope that helps. Quote Link to comment https://forums.phpfreaks.com/topic/218069-do-namespaces-exist-in-php/#findComment-1131773 Share on other sites More sharing options...
ignace Posted November 8, 2010 Share Posted November 8, 2010 Personally, I quite like the backslash as namespace separator. I like it too. It promotes the use of directories as a layering mechanism, it will make people start to think about their design when they are creating their n-th directory, and it eases auto-loading (no complex auto-loading schemes and more and more frameworks are adopting it). Quote Link to comment https://forums.phpfreaks.com/topic/218069-do-namespaces-exist-in-php/#findComment-1131878 Share on other sites More sharing options...
TomTees Posted November 9, 2010 Author Share Posted November 9, 2010 Noticed a LOT of small questions regarding different parts of more advanced PHP from Tom - might I advise you buy yourself a few decent books and read them. You can get the answer to this question within 10 seconds if you search google. Here's a link to another thread regarding good PHP books: http://www.phpfreaks.com/forums/miscellaneous/good-programming-and-web-design-books/ Hope that helps. Thanks for the link, but the reason I am here online is becasue books only go so far... TomTees Quote Link to comment https://forums.phpfreaks.com/topic/218069-do-namespaces-exist-in-php/#findComment-1132044 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.