registry.php類的聲明如下:
final class Registry {
private $data = array();
public function get($key) {
return (isset($this->data[$key]) ? $this->data[$key] : NULL);
}
public function set($key, $value) {
$this->data[$key] = $value;
}
public function has($key) {
return isset($this->data[$key]);
}
}
controller的聲明如下(截取部分):
abstract class Controller {
protected $registry;
protected $id;
protected $layout;
protected $template;
protected $children = array();
protected $data = array();
protected $output;
public function __construct($registry) {
$this->registry = $registry;
}
public function __get($key) {
return $this->registry->get($key);
}
public function __set($key, $value) {
$this->registry->set($key, $value);
}
}
任意聲明一些變量:
$arr=array("mantis"=>"task","hefei"=>"anhui");
$str="中國安徽合肥";
聲明一個類:
class db{
private $xx='123456';
private $data=array();
public function get($key) {
return (isset($this->data[$key]) ? $this->data[$key] : $key);
}
function connect(){
echo 'you are connecting...';
}
}
//聲明一個控制類:
class ControllerAccountFix extends Controller{
var $name;
var $age;
var $key='Opencat';
function __construct(){
$this->name='c';
$this->age='12';
}
function fix(){
echo $this->key.PHP_EOL;
}
}