复制代码 代码如下:
<?php
interface IUser{
function getName();
function getAge();
}
class User implements IUser{
protected $_name;
protected $_age;
function __construct($name, $age){
$this->_name = $name;
$this->_age = (int)$age;
}
function getName(){
return $this->_name;
}
function getAge(){
return $this->_age;
}
}
?>
复制代码 代码如下:
interface IUser{
function getName();
function getAge();
}
class User implements IUser{
protected $_group;
protected $_name;
protected $_age;
function __construct($name, $age, $group){
$this->_group = $group;
$this->_name = $name;
$this->_age = (int)$age;
}
function getName(){
return $this->_name;
}
function getAge(){
return $this->_age;
}
}
class Fuser{
private static $group = array(
array(‘小明‘,19,‘学生‘),
array(‘小王‘,19,‘学生‘)
);
static function create($id){
list($name, $age, $group) = self::$group[(int)$id];
return new User($name, $age, $group);
}
}
echo Fuser::create(0)->getName();
新闻热点
疑难解答