您好,欢迎访问一九零五行业门户网

PHP Collection类

无详细内容 无 ?phpheader(content-type:text/html; charset=utf-8);class collection{private $_members=array();private $_onload;private $_isloaded=false;public function startload(){$this-_checkcallback();}public function additem($obj,$key=nul
_checkcallback(); } public function additem($obj,$key=null){ $this->_checkcallback(); if($key){ if(isset($this->_members[$key])){ throw new exception(key \$key\ already in use!); }else{ $this->_members[$key]=$obj; } }else{ $this->_members[]=$obj; } } public function removeitem($key){ $this->_checkcallback(); if(isset($this->_members[$key])){ unset($this->_members[$key]); }else{ throw new exception(invalid key \$key\!); } } public function getitem($key){ $this->_checkcallback(); if(isset($this->_members[$key])){ return $this->_members[$key]; }else{ throw new exception(invalid key \$key\!); } } public function keys(){ $this->_checkcallback(); return array_keys($this->_members); } public function length(){ $this->_checkcallback(); return sizeof($this->_members); } public function exists($key){ $this->_checkcallback(); return (isset($this->_members[$key])); } public function setloadcallback($functionname,$objorclass=null){ if($objorclass){ $callback=array($objorclass,$functionname); }else{ $callback=$functionname; } if(!is_callable($callback)){ /*throw new exception($callablename is not callable.as a parameter to oonload);*/ echo $callback is not callable
; return false; } $this->_onload=$callback; } private function _checkcallback(){ if(isset($this->_onload)&&!$this->_isloaded){ $this->_isloaded=true; call_user_func($this->_onload,$this); } }}
其它类似信息

推荐信息