file1.php
<?php
namespace File1 ;
function foo()
{
echo "Used funection foo!\n" ;
}
?>
file2.php
<?php
namespace File2 ;
class Demo {
private $simpleVariable ;
public function __construct( $variable )
{
$this->simpleVariable=$variable ;
echo "A Demo has been constructed! named:".$this->simpleVariable."\n" ;
}
public function speak()
{
echo $this->simpleVariable ;
}
}
?>
file3.php
<?php
namespace File3 ;
const NUMBER=1024 ;
?>
main.php
<?php
require_once ("file1.php") ;
require_once ("file2.php") ;
require_once ("file3.php") ;
use function File1\foo ;
use File2\Demo ;
use const File3\NUMBER ;
$demo= new Demo("ZhangChengyi") ;
$demo-> speak() ;
echo NUMBER."\n" ;
foo() ;
?>
運(yùn)行結(jié)果
A Demo has been constructed! named:ZhangChengyi
ZhangChengyi
1024
Used funection foo!