## 關于命名空間
### 1. 命名空間的介紹
http://php.net/manual/zh/language.namespaces.rationale.php
1. 當工程越來越大,PHP文件會越來越多,產生的沖突也會越來越多。
2. 項目越來越大,功能越來越復雜,類也越來越多,如何管理這些類,使用到了「包」的概念,有層次的區分每一個類,使代碼越來越規范。
PHP 5.3以后支持命名空間。
### 2. 命名空間的定義
*D:\wamp\www\demo\oop\test1.php*
~~~
<?php
// namespace Test1;
function test()
{
echo __FILE__;
}
~~~
*D:\wamp\www\demo\oop\test2.php*
~~~
<?php
// namespace Test2;
function test()
{
echo __FILE__;
}
~~~
*D:\wamp\www\demo\oop\test.php*
~~~
<?php
include './test1.php';
include './test2.php';
~~~
*http://127.0.0.1/demo/oop/test.php*

只有開啟了 `namespace` 才能避免函數名重復的沖突出現。
PHP 命名空間提供了一種將相關的類、函數和常量組合到一起的途徑。
### 3. 命名空間的使用
[http://php.net/manual/zh/language.namespaces.basics.php](http://php.net/manual/zh/language.namespaces.basics.php)
*D:\wamp\www\demo\oop\test.php*
~~~
<?php
include './test1.php';
include './test2.php';
Test1\test();
Test2\test();
~~~
結果輸出:
~~~
D:\wamp\www\demo\oop\test1.phpD:\wamp\www\demo\oop\test2.php
~~~
- 序言
- 第1章 課程簡介
- 1-1 大話PHP設計模式課程簡介
- 第2章 開發環境準備
- 2-1 關于PHPStorm使用
- 2-2 關于編程字體選擇
- 2-3 關于運行環境搭建
- 第3章 命名空間與Autoload
- 3-1 關于命名空間
- 3-2 類自動載入
- 3-3 開發一個PSR-0的基礎框架
- 第4章 PHP面向對象
- 4-1 SPL標準庫簡介
- 4-2 PHP鏈式操作的實現
- 4-3 PHP魔術方法的使用
- 第5章 三種基礎設計模式
- 5-1 工廠模式
- 5-2 單例模式
- 5-3 注冊樹模式
- 第6章 適配器模式
- 6-1 適配器模式
- 第7章 策略模式
- 7-1 策略模式的實現和使用
- 7-2 策略模式的控制反轉
- 第8章 數據對象映射模式
- 8-1 數據對象映射模式之簡單案例實現
- 8-2 數據對象映射模式之復雜案例實現
- 第9章 觀察者模式
- 第10章 原型模式
- 第11章 裝飾器模式
- 第12章 迭代器模式
- 第13章 代理模式
- 第14章 綜合實戰
- 14-1 面向對象設計基本原則
- 14-2 MVC結構
- 14-3 自動加載配置
- 14-4 從配置中生成數據庫連接
- 14-5 裝飾器模式在MVC中的使用
- 14-6 觀察者模式在MVC程序中的使用
- 14-7 代理模式在MVC程序中的使用
- 14-8 課程小結