首页 > 代码库 > php namespace 方法与类

php namespace 方法与类

file1

<?php namespace foo;
class Cat {
static function says() {
echo ‘meoow‘;}
}

function demo(){
echo __FILE__;
}
?>

file2

<?php namespace bar;
class Dog {
static function says()
{
echo ‘ruff‘;
}
}

function demo(){
echo __FILE__;
}
?>

 

 

file

<?php namespace fub;
include ‘demo1.php‘;
include ‘demo2.php‘;
use foo as feline;
use bar as canine;

echo feline\Cat::says();
echo canine\Dog::says();

echo feline\demo();
echo canine\demo();
?>

 

php namespace 方法与类