index.php: <?php include ‘demo.php‘; use A\demo as test; use B\demo as test2; use C\demo; $obj = new test(); $obj = new test2(); echo B\b."<br>"; class c extends demo{ } $obj = new c(); $obj -> say(); demo:php <?php namespace A; class demo{ public function __construct(){ echo __NAMESPACE__."<br>"; } } namespace B; const b = ‘I am in namespace B‘; class demo{ public function __construct() { echo __NAMESPACE__."<br>"; } } namespace C; class demo{ public function say(){ echo ‘Class C say...‘; } }
时间: 2024-10-10 22:46:13