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