php的内置接口 arrayaccess
2017-07-03 00:22
267 查看
//ArrayAccess 是php内置的接口 可以把配置文件直接读出来 class Config implements ArrayAccess{ protected $path; protected $config = []; //'offsetGet', 'offsetUnset', 'offsetExists', 'offsetSet' public function __construct($path){ $this->path = $path; } //获取数组的key public function offsetGet($key){ if(empty($this->config[$key])){ echo $this->path; $file_path = $this->path.'/'.$key.'.php'; $config = require $file_path; $this->config[$key] = $config; } return $this->config[$key]; } public function offsetSet($key,$value){ } public function offsetUnset($key){ } public function offsetExists($key){ return isset($this->config[$key]); } } $config = new Config(__DIR__.'/config'); var_dump($config['config']);
相关文章推荐
- PHP的ArrayAccess接口 像数组一样来访问你的PHP对象
- PHP中的Iterator、ArrayAccess、Countable接口
- PHP 的 ArrayAccess 接口--像数组一样来访问你的 PHP 对象
- PHP的ArrayAccess接口简介
- PHP预定义接口之 ArrayAccess
- PHP的ArrayAccess接口 像数组一样来访问你的PHP对象
- 【php语法】实现ArrayAccess接口,以数组的形式访问对象
- PHP数组式访问接口 ArrayAccess
- php系统内置的 观察者模式接口
- PHP - ArrayAccess接口详解
- PHP数组式访问接口ArrayAccess用法分析
- PHP 的ArrayAccess接口 像数组一样来访问你的PHP对象
- PHP预定义接口之 ArrayAccess
- PHP预定义接口之 ArrayAccess
- php写的短信接口(全网支持)
- 如何利用内置PHP灵活性执行外部程序
- [导入]关于PHP接口的学习
- 发一个自己原创的迷你博客的PHP源程序(支持QQ、MSN和飞信机器人和短息接口)
- PHP内置字符串函数实现