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