1 2 3 4 5 6 7 8 9 10 11 12 | class Dictionary { public $translations = array(); public $type ="En"; function summarize() { $ret = "Dictionary type: {$this->type}\n"; $ret .= "Terms: ".count( $this->translations )."\n"; return $ret; } } $en = new Dictionary(); $en->translations['TREE'] = "tree"; print $en->summarize(); |
1 2 | Dictionary type: En Terms: 1 |
1 2 3 4 5 6 7 8 9 | class Dictionary { public $translations = array(); public $type; public $dictio; function __construct( $type, DictionaryIO $dictio ) { $this->type = $type; $this->dictio=$dictio; } //... |
1 | $en = new Dictionary( "En", new DictionaryIO() ); |
1 2 3 4 5 6 7 8 9 10 11 12 | class Dictionary { private $translations = array(); private $dictio; private $type; function __construct( $type, DictionaryIO $dictio ) { $this->type = $type; $this->dictio = $dictio; } // ... } $en = new Dictionary( "En", new DictionaryIO() ); $en->dictio = null; |
1 2 | Fatal error: Cannot access private property Dictionary:dictio in... |
1 2 3 4 5 6 7 8 | function get( $term ) { $value = $this->translations[$term]; $this->logQuery( $term, $value, "get" ); return $value; } private function logQuery( $term, $value, $kind ) { // write log information } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |