Skip to content

[VarDumper] Fix dumping type hints for non-existing parent classes #18593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/Symfony/Component/VarDumper/Caster/ReflectionCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,11 @@ public static function castParameter(\ReflectionParameter $c, array $a, Stub $st
if ($c->hasType()) {
$a[$prefix.'typeHint'] = $c->getType()->__toString();
}
} elseif ($c->isArray()) {
$a[$prefix.'typeHint'] = 'array';
} elseif (method_exists($c, 'isCallable') && $c->isCallable()) {
$a[$prefix.'typeHint'] = 'callable';
} elseif ($v = $c->getClass()) {
$a[$prefix.'typeHint'] = $v->name;
} else {
$v = explode(' ', $c->__toString(), 6);
if (isset($v[5]) && 0 === strspn($v[4], '.&$')) {
$a[$prefix.'typeHint'] = $v[4];
}
}
} catch (\ReflectionException $e) {
if (preg_match('/^Class ([^ ]++) does not exist$/', $e->getMessage(), $m)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\VarDumper\Tests\Caster;

use Symfony\Component\VarDumper\Test\VarDumperTestCase;
use Symfony\Component\VarDumper\Tests\Fixtures\NotLoadableClass;

/**
* @author Nicolas Grekas <p@tchwork.com>
Expand Down Expand Up @@ -47,7 +48,7 @@ public function testReflectionCaster()
"export" => ReflectionMethod {
+name: "export"
+class: "ReflectionClass"
parameters: array:2 [
%A parameters: array:2 [
"$%s" => ReflectionParameter {
%A position: 0
%A }
Expand All @@ -70,7 +71,7 @@ public function testReflectionParameter()
ReflectionParameter {
+name: "arg1"
position: 0
typeHint: "Symfony\Component\VarDumper\Tests\Caster\NotExistingClass"
typeHint: "Symfony\Component\VarDumper\Tests\Fixtures\NotLoadableClass"
default: null
}
EOTXT
Expand Down Expand Up @@ -121,6 +122,6 @@ class: "Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest"
}
}

function reflectionParameterFixture(NotExistingClass $arg1 = null, $arg2)
function reflectionParameterFixture(NotLoadableClass $arg1 = null, $arg2)
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Symfony\Component\VarDumper\Tests\Fixtures;

class NotLoadableClass extends NotLoadableClass
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a class extending itself ? Are you missing the time of your Patchwork framework ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do :) That's the test case here: a class that would fail to be loaded :)

{
}