Skip to content

Commit 65984ba

Browse files
committed
main
1 parent bda879e commit 65984ba

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed

src/Lib.php

+37-6
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ public static function php_var_dump($value, array $options = []) : string
144144
{
145145
$maxlen = $options[ 'maxlen' ] ?? null;
146146
$withArrays = $options[ 'with_arrays' ] ?? true;
147+
$withIds = $options[ 'with_ids' ] ?? true;
147148

148149
if ($maxlen < 1) $maxlen = null;
149150

@@ -152,7 +153,11 @@ public static function php_var_dump($value, array $options = []) : string
152153

153154
if (is_iterable($value)) {
154155
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 . ')';
156161

157162
} else {
158163
$var = 'array(' . count($value) . ')';
@@ -176,7 +181,11 @@ public static function php_var_dump($value, array $options = []) : string
176181

177182
} else {
178183
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 . ')';
180189

181190
if (method_exists($value, '__debugInfo')) {
182191
ob_start();
@@ -187,10 +196,14 @@ public static function php_var_dump($value, array $options = []) : string
187196
} elseif (is_string($value)) {
188197
$var = 'string(' . strlen($value) . ')';
189198

190-
$dump = "\"{$value}\"";
199+
$dump = "\"{$dump}\"";
191200

192201
} 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 . ') }';
194207

195208
} else {
196209
$var = null
@@ -235,6 +248,7 @@ public static function php_var_export($var, array $options = []) : string
235248
$indent = $options[ 'indent' ] ?? " ";
236249
$newline = $options[ 'newline' ] ?? PHP_EOL;
237250
$withObjects = $options[ 'with_objects' ] ?? true;
251+
$withIds = $options[ 'with_ids' ] ?? true;
238252

239253
switch ( gettype($var) ) {
240254
case "NULL":
@@ -250,7 +264,6 @@ public static function php_var_export($var, array $options = []) : string
250264
break;
251265

252266
case "array":
253-
254267
$keys = array_keys($var);
255268

256269
foreach ( $keys as $key ) {
@@ -292,7 +305,25 @@ public static function php_var_export($var, array $options = []) : string
292305
$result = var_export($var, true);
293306

294307
} 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 . ') }';
296327
}
297328

298329
break;

0 commit comments

Comments
 (0)