Skip to content

Commit 3366008

Browse files
bug symfony#25209 [VarDumper] Dont use empty(), it chokes on eg GMP objects (nicolas-grekas)
This PR was merged into the 3.3 branch. Discussion ---------- [VarDumper] Dont use empty(), it chokes on eg GMP objects | Q | A | ------------- | --- | Branch? | 3.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#25198 | License | MIT | Doc PR | - Commits ------- 1b14173 [VarDumper] Dont use empty(), it chokes on eg GMP objects
2 parents 26fb4c7 + 1b14173 commit 3366008

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/Symfony/Component/VarDumper/Caster/Caster.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ public static function filter(array $a, $filter, array $listedProperties = array
118118

119119
if (null === $v) {
120120
$type |= self::EXCLUDE_NULL & $filter;
121-
}
122-
if (empty($v)) {
121+
$type |= self::EXCLUDE_EMPTY & $filter;
122+
} elseif (false === $v || '' === $v || '0' === $v || 0 === $v || 0.0 === $v || array() === $v) {
123123
$type |= self::EXCLUDE_EMPTY & $filter;
124124
}
125125
if ((self::EXCLUDE_NOT_IMPORTANT & $filter) && !in_array($k, $listedProperties, true)) {

src/Symfony/Component/VarDumper/Cloner/VarCloner.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,16 @@ protected function doClone($var)
9494
// Create $stub when the original value $v can not be used directly
9595
// If $v is a nested structure, put that structure in array $a
9696
switch (true) {
97-
case empty($v):
98-
case true === $v:
97+
case null === $v:
98+
case \is_bool($v):
9999
case \is_int($v):
100100
case \is_float($v):
101101
continue 2;
102102

103103
case \is_string($v):
104+
if ('' === $v) {
105+
continue 2;
106+
}
104107
if (!\preg_match('//u', $v)) {
105108
$stub = new Stub();
106109
$stub->type = Stub::TYPE_STRING;
@@ -124,6 +127,9 @@ protected function doClone($var)
124127
break;
125128

126129
case \is_array($v):
130+
if (!$v) {
131+
continue 2;
132+
}
127133
$stub = $arrayStub;
128134
$stub->class = Stub::ARRAY_INDEXED;
129135

0 commit comments

Comments
 (0)