8000 [VarDumper] Towards PHP7 support · symfony/symfony@8d5f480 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 8d5f480

Browse files
[VarDumper] Towards PHP7 support
1 parent 7adba99 commit 8d5f480

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,19 @@ class ExceptionCaster
4242

4343
public static function castException(\Exception $e, array $a, Stub $stub, $isNested)
4444
{
45-
$trace = $a["\0Exception\0trace"];
46-
unset($a["\0Exception\0trace"]); // Ensures the trace is always last
45+
$xPrefix = PHP_VERSION_ID >= 700000 ? "\0BaseException\0" : "\0Exception\0";
46+
$trace = $a[$xPrefix.'trace'];
47+
unset($a[$xPrefix.'trace']); // Ensures the trace is always last
4748

4849
static::filterTrace($trace, static::$traceArgs);
4950

5051
if (null !== $trace) {
51-
$a["\0Exception\0trace"] = $trace;
52+
$a[$xPrefix.'trace'] = $trace;
5253
}
53-
if (empty($a["\0Exception\0previous"])) {
54-
unset($a["\0Exception\0previous"]);
54+
if (empty($a[$xPrefix.'previous'])) {
55+
unset($a[$xPrefix.'previous']);
5556
}
56-
unset($a["\0Exception\0string"], $a["\0+\0xdebug_message"], $a["\0+\0__destructorException"]);
57+
unset($a[$xPrefix.'string'], $a["\0+\0xdebug_message"], $a["\0+\0__destructorException"]);
5758

5859
return $a;
5960
}
@@ -69,23 +70,24 @@ public static function castErrorException(\ErrorException $e, array $a, Stub $st
6970

7071
public static function castThrowingCasterException(ThrowingCasterException $e, array $a, Stub $stub, $isNested)
7172
{
72-
$b = (array) $a["\0Exception\0previous"];
73+
$xPrefix = PHP_VERSION_ID >= 700000 ? "\0BaseException\0" : "\0Exception\0";
74+
$b = (array) $a[$xPrefix.'previous'];
7375

7476
if (isset($b["\0*\0message"])) {
7577
$a["\0~\0message"] = $b["\0*\0message"];
7678
}
7779

78-
if (isset($a["\0Exception\0trace"])) {
79-
$b["\0Exception\0trace"][0] += array(
80+
if (isset($a[$xPrefix.'trace'])) {
81+
$b[$xPrefix.'trace'][0] += array(
8082
'file' => $b["\0*\0file"],
8183
'line' => $b["\0*\0line"],
8284
);
83-
array_splice($b["\0Exception\0trace"], -1 - count($a["\0Exception\0trace"]));
84-
static::filterTrace($b["\0Exception\0trace"], false);
85-
$a["\0~\0trace"] = $b["\0Exception\0trace"];
85+
array_splice($b[$xPrefix.'trace'], -1 - count($a[$xPrefix.'trace']));
86+
static::filterTrace($b[$xPrefix.'trace'], false);
87+
$a["\0~\0trace"] = $b[$xPrefix.'trace'];
8688
}
8789

88-
unset($a["\0Exception\0trace"], $a["\0Exception\0previous"], $a["\0*\0code"], $a["\0*\0file"], $a["\0*\0line"]);
90+
unset($a[$xPrefix.'trace'], $a[$xPrefix.'previous'], $a["\0*\0code"], $a["\0*\0file"], $a["\0*\0line"]);
8991

9092
return $a;
9193
}

src/Symfony/Component/VarDumper/Tests/CliDumperTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ public function testGet()
3838
ob_start();
3939
$dumper->dump($data);
4040
$out = ob_get_clean();
41-
$closureLabel = PHP_VERSION_ID >= 50400 ? 'public method' : 'function';
4241
$out = preg_replace('/[ \t]+$/m', '', $out);
4342
$intMax = PHP_INT_MAX;
4443
$res1 = (int) $var['res'];
@@ -77,7 +76,7 @@ public function testGet()
7776
}
7877
"closure" => Closure {#%d
7978
reflection: """
80-
Closure [ <user> {$closureLabel} Symfony\Component\VarDumper\Tests\Fixture\{closure} ] {
79+
Closure [ <user> %s Symfony\Component\VarDumper\Tests\Fixture\{closure} ] {
8180
@@ {$var['file']} {$var['line']} - {$var['line']}
8281
8382
- Parameters [2] {

src/Symfony/Component/VarDumper/Tests/HtmlDumperTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ public function testGet()
3939
ob_start();
4040
$dumper->dump($data);
4141
$out = ob_get_clean();
42-
$closureLabel = PHP_VERSION_ID >= 50400 ? 'public method' : 'function';
4342
$out = preg_replace('/[ \t]+$/m', '', $out);
4443
$var['file'] = htmlspecialchars($var['file'], ENT_QUOTES, 'UTF-8');
4544
$intMax = PHP_INT_MAX;
@@ -81,7 +80,7 @@ public function testGet()
8180
</samp>}
8281
"<span class=sf-dump-key>closure</span>" => <span class=sf-dump-note>Closure</span> {<a class=sf-dump-ref>#%d</a><samp>
8382
<span class=sf-dump-meta>reflection</span>: """
84-
<span class=sf-dump-str title="%d characters">Closure [ &lt;user&gt; {$closureLabel} Symfony\Component\VarDumper\Tests\Fixture\{closure} ] {</span>
83+
<span class=sf-dump-str title="%d characters">Closure [ &lt;user&gt; %s
8584
<span class=sf-dump-str title="%d characters"> @@ {$var['file']} {$var['line']} - {$var['line']}</span>
8685
8786
<span class=sf-dump-str title="%d characters"> - Parameters [2] {</span>

0 commit comments

Comments
 (0)
0