1--TEST-- 2OO API: SNMP object properties 3--CREDITS-- 4Boris Lytochkin 5--EXTENSIONS-- 6snmp 7--SKIPIF-- 8<?php 9require_once(__DIR__.'/skipif.inc'); 10?> 11--FILE-- 12<?php 13require_once(__DIR__.'/snmp_include.inc'); 14 15//EXPECTF format is quickprint OFF 16snmp_set_enum_print(false); 17snmp_set_quick_print(false); 18snmp_set_valueretrieval(SNMP_VALUE_PLAIN); 19snmp_set_oid_output_format(SNMP_OID_OUTPUT_FULL); 20 21echo "Check working\n"; 22 23$session = new SNMP(SNMP::VERSION_1, $hostname, $community, $timeout, $retries); 24var_dump($session); 25 26$session->max_oids = 40; 27$session->enum_print = TRUE; 28$session->quick_print = TRUE; 29$session->valueretrieval = SNMP_VALUE_LIBRARY; 30$session->oid_output_format = SNMP_OID_OUTPUT_NUMERIC; 31$session->oid_increasing_check = FALSE; 32 33var_dump($session); 34 35$session->max_oids = "40"; 36$session->enum_print = "1"; 37$session->quick_print = "1"; 38$session->valueretrieval = "1"; 39$session->oid_output_format = "3"; 40$session->oid_increasing_check = "45"; 41 42var_dump($session); 43 44var_dump(property_exists($session, "enum_print")); 45var_dump(isset($session->enum_print)); 46var_dump(empty($session->enum_print)); 47 48$param=123; 49$session->$param = "param_value"; 50var_dump($session); 51var_dump($session->$param); 52var_dump(property_exists($session, $param)); 53 54echo "Error handling\n"; 55$param = 'there is no such parameter'; 56var_dump($session->$param); 57var_dump(property_exists($session, $param)); 58 59try { 60 $session->valueretrieval = 67; 61 var_dump($session->valueretrieval); 62} catch (\ValueError $e) { 63 echo $e->getMessage() . \PHP_EOL; 64} 65try { 66 $session->oid_output_format = 78; 67 var_dump($session->oid_output_format); 68} catch (\ValueError $e) { 69 echo $e->getMessage() . \PHP_EOL; 70} 71try { 72 $session->info = array("blah" => 2); 73 var_dump($session->info); 74} catch (\Error $e) { 75 echo $e->getMessage() . \PHP_EOL; 76} 77 78$session->max_oids = NULL; 79var_dump($session->max_oids); 80?> 81--EXPECTF-- 82Check working 83object(SNMP)#%d (%d) { 84 ["info"]=> 85 array(3) { 86 ["hostname"]=> 87 string(%d) "%s" 88 ["timeout"]=> 89 int(%i) 90 ["retries"]=> 91 int(%d) 92 } 93 ["max_oids"]=> 94 NULL 95 ["valueretrieval"]=> 96 int(1) 97 ["quick_print"]=> 98 bool(false) 99 ["enum_print"]=> 100 bool(false) 101 ["oid_output_format"]=> 102 int(3) 103 ["oid_increasing_check"]=> 104 bool(true) 105 ["exceptions_enabled"]=> 106 int(0) 107} 108object(SNMP)#%d (%d) { 109 ["info"]=> 110 array(3) { 111 ["hostname"]=> 112 string(%d) "%s" 113 ["timeout"]=> 114 int(%i) 115 ["retries"]=> 116 int(%d) 117 } 118 ["max_oids"]=> 119 int(40) 120 ["valueretrieval"]=> 121 int(0) 122 ["quick_print"]=> 123 bool(true) 124 ["enum_print"]=> 125 bool(true) 126 ["oid_output_format"]=> 127 int(4) 128 ["oid_increasing_check"]=> 129 bool(false) 130 ["exceptions_enabled"]=> 131 int(0) 132} 133object(SNMP)#%d (%d) { 134 ["info"]=> 135 array(3) { 136 ["hostname"]=> 137 string(%d) "%s" 138 ["timeout"]=> 139 int(%i) 140 ["retries"]=> 141 int(%d) 142 } 143 ["max_oids"]=> 144 int(40) 145 ["valueretrieval"]=> 146 int(1) 147 ["quick_print"]=> 148 bool(true) 149 ["enum_print"]=> 150 bool(true) 151 ["oid_output_format"]=> 152 int(3) 153 ["oid_increasing_check"]=> 154 bool(true) 155 ["exceptions_enabled"]=> 156 int(0) 157} 158bool(true) 159bool(true) 160bool(false) 161 162Deprecated: Creation of dynamic property SNMP::$123 is deprecated in %s on line %d 163object(SNMP)#%d (%d) { 164 ["info"]=> 165 array(3) { 166 ["hostname"]=> 167 string(%d) "%s" 168 ["timeout"]=> 169 int(%i) 170 ["retries"]=> 171 int(%d) 172 } 173 ["max_oids"]=> 174 int(40) 175 ["valueretrieval"]=> 176 int(1) 177 ["quick_print"]=> 178 bool(true) 179 ["enum_print"]=> 180 bool(true) 181 ["oid_output_format"]=> 182 int(3) 183 ["oid_increasing_check"]=> 184 bool(true) 185 ["exceptions_enabled"]=> 186 int(0) 187 ["123"]=> 188 string(11) "param_value" 189} 190string(11) "param_value" 191bool(true) 192Error handling 193 194Warning: Undefined property: SNMP::$there is no such parameter in %s on line %d 195NULL 196bool(false) 197SNMP retrieval method must be a bitmask of SNMP_VALUE_LIBRARY, SNMP_VALUE_PLAIN, and SNMP_VALUE_OBJECT 198SNMP output print format must be an SNMP_OID_OUTPUT_* constant 199Cannot write read-only property SNMP::$info 200NULL 201