標籤:
Name collisions means: you create a function named db_connect, and somebody elses code that you use in your file (i.e. an include) has the same function with the same name. To get around that problem, you rename your function SteveWa_db_connect which makes your code longer and harder to read. Now you can use namespaces to keep your function name separate from anyone else‘s function name, and you won‘t have to make extra_long_named functions to get around the name collision problem. So a namespace is like a pointer to a file path where you can find the source of the function you are working with
(譯文)名字衝突意味著:
你建立了一個函數named db_connect,然後你用了某個跟你有相同函數名的代碼(例如:一個include)。為瞭解決函數名衝突的問題,你把原來的函數named db_connect重新命名為SteveWa_db_connect,這種形式讓你的名字更加長,而且更難閱讀。
現在你使用命名空間namespaces來確保你的函數named db_connect跟另外一個你引用的同名函數區分開,與此同時你不需要額外的長首碼來解決函數名衝突。所以,命名空間namespace更像一個檔案指路者,來卻把你想用的檔案路徑是正確的。
PHP學習筆記:對命名空間(namespace)學習資料的翻譯