(PHP 5 >= 5.3.0, PHP 7)
锟斤拷说锟斤拷锟斤拷锟狡斤拷锟斤拷锟斤拷锟斤拷之前锟斤拷锟斤拷锟斤拷锟饺匡拷一些锟斤拷要锟侥讹拷锟藉:
锟斤拷锟斤拷锟叫诧拷锟斤拷锟斤拷锟斤拷锟斤拷锟秸硷拷指锟斤拷锟斤拷谋锟绞讹拷锟斤拷锟斤拷锟斤拷锟� Foo
锟斤拷锟斤拷锟叫猴拷锟斤拷锟斤拷锟斤拷锟秸硷拷指锟斤拷锟斤拷谋锟绞讹拷锟斤拷锟斤拷锟斤拷锟� Foo\Bar
锟斤拷锟斤拷锟叫帮拷锟斤拷锟斤拷锟斤拷锟秸硷拷指锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷占锟街革拷锟斤拷锟斤拷始锟侥憋拷识锟斤拷锟斤拷锟斤拷锟斤拷 \Foo\Bar锟斤拷 namespace\Foo 也锟斤拷一锟斤拷锟斤拷全锟睫讹拷锟斤拷锟狡★拷
锟斤拷锟狡斤拷锟斤拷锟斤拷循锟斤拷锟叫癸拷锟斤拷
Example #1 锟斤拷锟狡斤拷锟斤拷示锟斤拷
<?php
namespace A;
use B\D, C\E as F;
// 锟斤拷锟斤拷锟斤拷锟斤拷
foo(); // 锟斤拷锟饺筹拷锟皆碉拷锟矫讹拷锟斤拷锟斤拷锟斤拷锟斤拷锟秸硷拷"A"锟叫的猴拷锟斤拷foo()
// 锟劫筹拷锟皆碉拷锟斤拷全锟街猴拷锟斤拷 "foo"
\foo(); // 锟斤拷锟斤拷全锟街空间函锟斤拷 "foo"
my\foo(); // 锟斤拷锟矫讹拷锟斤拷锟斤拷锟斤拷锟斤拷锟秸硷拷"A\my"锟叫猴拷锟斤拷 "foo"
F(); // 锟斤拷锟饺筹拷锟皆碉拷锟矫讹拷锟斤拷锟斤拷锟斤拷锟斤拷锟秸硷拷"A"锟叫的猴拷锟斤拷 "F"
// 锟劫筹拷锟皆碉拷锟斤拷全锟街猴拷锟斤拷 "F"
// 锟斤拷锟斤拷锟斤拷
new B(); // 锟斤拷锟斤拷锟斤拷锟斤拷锟秸硷拷 "A" 锟叫讹拷锟斤拷锟斤拷锟� "B" 锟斤拷一锟斤拷锟斤拷锟斤拷
// 锟斤拷锟轿达拷业锟斤拷锟斤拷锟斤拷锟斤拷远锟阶帮拷锟斤拷锟� "A\B"
new D(); // 使锟矫碉拷锟斤拷锟斤拷颍锟斤拷锟斤拷锟斤拷锟斤拷占锟� "B" 锟叫讹拷锟斤拷锟斤拷锟� "D" 锟斤拷一锟斤拷锟斤拷锟斤拷
// 锟斤拷锟轿达拷业锟斤拷锟斤拷锟斤拷锟斤拷远锟阶帮拷锟斤拷锟� "B\D"
new F(); // 使锟矫碉拷锟斤拷锟斤拷颍锟斤拷锟斤拷锟斤拷锟斤拷占锟� "C" 锟叫讹拷锟斤拷锟斤拷锟� "E" 锟斤拷一锟斤拷锟斤拷锟斤拷
// 锟斤拷锟轿达拷业锟斤拷锟斤拷锟斤拷锟斤拷远锟阶帮拷锟斤拷锟� "C\E"
new \B(); // 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷全锟街空硷拷锟叫碉拷锟斤拷 "B" 锟斤拷一锟斤拷锟斤拷锟斤拷
// 锟斤拷锟轿达拷锟斤拷郑锟斤拷锟斤拷锟斤拷远锟阶帮拷锟斤拷锟� "B"
new \D(); // 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷全锟街空硷拷锟叫碉拷锟斤拷 "D" 锟斤拷一锟斤拷锟斤拷锟斤拷
// 锟斤拷锟轿达拷锟斤拷郑锟斤拷锟斤拷锟斤拷远锟阶帮拷锟斤拷锟� "D"
new \F(); // 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷全锟街空硷拷锟叫碉拷锟斤拷 "F" 锟斤拷一锟斤拷锟斤拷锟斤拷
// 锟斤拷锟轿达拷锟斤拷郑锟斤拷锟斤拷锟斤拷远锟阶帮拷锟斤拷锟� "F"
// 锟斤拷锟斤拷锟斤拷一锟斤拷锟斤拷锟斤拷锟秸硷拷锟叫的撅拷态锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟秸间函锟斤拷
B\foo(); // 锟斤拷锟斤拷锟斤拷锟斤拷锟秸硷拷 "A\B" 锟叫猴拷锟斤拷 "foo"
B::foo(); // 锟斤拷锟斤拷锟斤拷锟斤拷锟秸硷拷 "A" 锟叫讹拷锟斤拷锟斤拷锟� "B" 锟斤拷 "foo" 锟斤拷锟斤拷
// 锟斤拷锟轿达拷业锟斤拷锟� "A\B" 锟斤拷锟斤拷锟斤拷锟皆讹拷装锟斤拷锟斤拷 "A\B"
D::foo(); // 使锟矫碉拷锟斤拷锟斤拷颍锟斤拷锟斤拷锟斤拷锟斤拷占锟� "B" 锟叫讹拷锟斤拷锟斤拷锟� "D" 锟斤拷 "foo" 锟斤拷锟斤拷
// 锟斤拷锟斤拷锟� "B\D" 未锟揭碉拷锟斤拷锟斤拷锟斤拷锟皆讹拷装锟斤拷锟斤拷 "B\D"
\B\foo(); // 锟斤拷锟斤拷锟斤拷锟斤拷锟秸硷拷 "B" 锟叫的猴拷锟斤拷 "foo"
\B::foo(); // 锟斤拷锟斤拷全锟街空硷拷锟叫碉拷锟斤拷 "B" 锟斤拷 "foo" 锟斤拷锟斤拷
// 锟斤拷锟斤拷锟� "B" 未锟揭碉拷锟斤拷锟斤拷锟斤拷锟皆讹拷装锟斤拷锟斤拷 "B"
// 锟斤拷前锟斤拷锟斤拷锟秸硷拷锟叫的撅拷态锟斤拷锟斤拷锟斤拷锟斤拷
A\B::foo(); // 锟斤拷锟斤拷锟斤拷锟斤拷锟秸硷拷 "A\A" 锟叫讹拷锟斤拷锟斤拷锟� "B" 锟斤拷 "foo" 锟斤拷锟斤拷
// 锟斤拷锟斤拷锟� "A\A\B" 未锟揭碉拷锟斤拷锟斤拷锟斤拷锟皆讹拷装锟斤拷锟斤拷 "A\A\B"
\A\B::foo(); // 锟斤拷锟斤拷锟斤拷锟斤拷锟秸硷拷 "A\B" 锟叫讹拷锟斤拷锟斤拷锟� "B" 锟斤拷 "foo" 锟斤拷锟斤拷
// 锟斤拷锟斤拷锟� "A\B" 未锟揭碉拷锟斤拷锟斤拷锟斤拷锟皆讹拷装锟斤拷锟斤拷 "A\B"
?>