原文来自:http://blog.chinaunix.net/uid-7654720-id-3211234.html
class SNMP_Wrapper { protected $_host; protected $_community; protected $_version; public function __construct($host = 'localhost', $community = 'public', $version = 1) { $this->_host = $host; $this->_community = $community; switch ($version) { case 2: $this->_version = '2'; break; case 3: $this->_version = '3'; break;//注意,原文缺少了break,造成使用版本3时会调用默认的版本1的函数 default: $this->_version = ''; break; } } public function __call($func, $args) { $func = strtolower(preg_replace('/([A-Z])/', '_$1', $func)); $function = 'snmp' . $this->_version . (empty($this->_version) ? '' : '_') . $func; if (function_exists($function)) { var_dump($function); return call_user_func_array($function, array_merge(array($this->_host, $this->_community), $args)); } } } //debug $snmp = new SNMP_Wrapper("127.0.0.1", "public", 3); $result = @$snmp->get("iso.3.6.1.2.1.1.3.0"); var_dump($result);exit;