Jump to content

Do Namespaces exist in PHP?


TomTees

Recommended Posts

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

 

 

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.  :shy:

 

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.

 

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.

Personally, I quite like the backslash as namespace separator.  :shy:

 

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).

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

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.