@@ -144,6 +144,7 @@ public static function php_var_dump($value, array $options = []) : string
144
144
{
145
145
$ maxlen = $ options [ 'maxlen ' ] ?? null ;
146
146
$ withArrays = $ options [ 'with_arrays ' ] ?? true ;
147
+ $ withIds = $ options [ 'with_ids ' ] ?? true ;
147
148
148
149
if ($ maxlen < 1 ) $ maxlen = null ;
149
150
@@ -152,7 +153,11 @@ public static function php_var_dump($value, array $options = []) : string
152
153
153
154
if (is_iterable ($ value )) {
154
155
if (is_object ($ value )) {
155
- $ var = 'iterable( ' . get_class ($ value ) . ' # ' . spl_object_id ($ value ) . ') ' ;
156
+ $ id = $ withIds
157
+ ? ' # ' . spl_object_id ($ value )
158
+ : '' ;
159
+
160
+ $ var = 'iterable( ' . get_class ($ value ) . $ id . ') ' ;
156
161
157
162
} else {
158
163
$ var = 'array( ' . count ($ value ) . ') ' ;
@@ -176,7 +181,11 @@ public static function php_var_dump($value, array $options = []) : string
176
181
177
182
} else {
178
183
if (is_object ($ value )) {
179
- $ var = 'object( ' . get_class ($ value ) . ' # ' . spl_object_id ($ value ) . ') ' ;
184
+ $ id = $ withIds
185
+ ? ' # ' . spl_object_id ($ value )
186
+ : '' ;
187
+
188
+ $ var = 'object( ' . get_class ($ value ) . $ id . ') ' ;
180
189
181
190
if (method_exists ($ value , '__debugInfo ' )) {
182
191
ob_start ();
@@ -187,10 +196,14 @@ public static function php_var_dump($value, array $options = []) : string
187
196
} elseif (is_string ($ value )) {
188
197
$ var = 'string( ' . strlen ($ value ) . ') ' ;
189
198
190
- $ dump = "\"{$ value }\"" ;
199
+ $ dump = "\"{$ dump }\"" ;
191
200
192
201
} elseif (is_resource ($ value )) {
193
- $ var = '{ resource( ' . gettype ($ value ) . ' # ' . ((int ) $ value ) . ') } ' ;
202
+ $ id = $ withIds
203
+ ? ' # ' . ((int ) $ value )
204
+ : '' ;
205
+
206
+ $ var = '{ resource( ' . get_resource_type ($ value ) . $ id . ') } ' ;
194
207
195
208
} else {
196
209
$ var = null
@@ -235,6 +248,7 @@ public static function php_var_export($var, array $options = []) : string
235
248
$ indent = $ options [ 'indent ' ] ?? " " ;
236
249
$ newline = $ options [ 'newline ' ] ?? PHP_EOL ;
237
250
$ withObjects = $ options [ 'with_objects ' ] ?? true ;
251
+ $ withIds = $ options [ 'with_ids ' ] ?? true ;
238
252
239
253
switch ( gettype ($ var ) ) {
240
254
case "NULL " :
@@ -250,7 +264,6 @@ public static function php_var_export($var, array $options = []) : string
250
264
break ;
251
265
252
266
case "array " :
253
-
254
267
$ keys = array_keys ($ var );
255
268
256
269
foreach ( $ keys as $ key ) {
@@ -292,7 +305,25 @@ public static function php_var_export($var, array $options = []) : string
292
305
$ result = var_export ($ var , true );
293
306
294
307
} else {
295
- $ result = '{ object( ' . get_class ($ var ) . ' # ' . spl_object_id ($ var ) . ') } ' ;
308
+ $ id = $ withIds
309
+ ? ' # ' . spl_object_id ($ var )
310
+ : null ;
311
+
312
+ $ result = '{ object( ' . get_class ($ var ) . $ id . ') } ' ;
313
+ }
314
+
315
+ break ;
316
+
317
+ case "resource " :
318
+ if ($ withObjects ) {
319
+ $ result = var_export ($ var , true );
320
+
321
+ } else {
322
+ $ id = $ withIds
323
+ ? ' # ' . spl_object_id ($ var )
324
+ : null ;
325
+
326
+ $ result = '{ resource( ' . get_resource_type ($ var ) . $ id . ') } ' ;
296
327
}
297
328
298
329
break ;
0 commit comments