[2.7][VarDumper] Fix PHP 7.1 compat

This commit is contained in:
Nicolas Grekas 2016-09-29 12:05:17 +01:00
parent 07d4985024
commit 466dbe62b4

View File

@ -115,7 +115,7 @@ class ReflectionCaster
)); ));
if (isset($a[$prefix.'returnType'])) { if (isset($a[$prefix.'returnType'])) {
$a[$prefix.'returnType'] = (string) $a[$prefix.'returnType']; $a[$prefix.'returnType'] = method_exists('ReflectionType', 'getName') ? $a[$prefix.'returnType']->getName() : $a[$prefix.'returnType']->__toString();
} }
if (isset($a[$prefix.'this'])) { if (isset($a[$prefix.'this'])) {
$a[$prefix.'this'] = new CutStub($a[$prefix.'this']); $a[$prefix.'this'] = new CutStub($a[$prefix.'this']);
@ -164,12 +164,13 @@ class ReflectionCaster
'position' => 'getPosition', 'position' => 'getPosition',
'isVariadic' => 'isVariadic', 'isVariadic' => 'isVariadic',
'byReference' => 'isPassedByReference', 'byReference' => 'isPassedByReference',
'allowsNull' => 'allowsNull',
)); ));
try { try {
if (method_exists($c, 'hasType')) { if (method_exists($c, 'hasType')) {
if ($c->hasType()) { if ($c->hasType()) {
$a[$prefix.'typeHint'] = $c->getType()->__toString(); $a[$prefix.'typeHint'] = method_exists('ReflectionType', 'getName') ? $c->getType()->getName() : $c->getType()->__toString();
} }
} else { } else {
$v = explode(' ', $c->__toString(), 6); $v = explode(' ', $c->__toString(), 6);
@ -182,15 +183,22 @@ class ReflectionCaster
$a[$prefix.'typeHint'] = $m[1]; $a[$prefix.'typeHint'] = $m[1];
} }
} }
if (!isset($a[$prefix.'typeHint'])) {
unset($a[$prefix.'allowsNull']);
}
try { try {
$a[$prefix.'default'] = $v = $c->getDefaultValue(); $a[$prefix.'default'] = $v = $c->getDefaultValue();
if (method_exists($c, 'isDefaultValueConstant') && $c->isDefaultValueConstant()) { if (method_exists($c, 'isDefaultValueConstant') && $c->isDefaultValueConstant()) {
$a[$prefix.'default'] = new ConstStub($c->getDefaultValueConstantName(), $v); $a[$prefix.'default'] = new ConstStub($c->getDefaultValueConstantName(), $v);
} }
if (null === $v) {
unset($a[$prefix.'allowsNull']);
}
} catch (\ReflectionException $e) { } catch (\ReflectionException $e) {
if (isset($a[$prefix.'typeHint']) && $c->allowsNull()) { if (isset($a[$prefix.'typeHint']) && $c->allowsNull() && !method_exists('ReflectionType', 'getName')) {
$a[$prefix.'default'] = null; $a[$prefix.'default'] = null;
unset($a[$prefix.'allowsNull']);
} }
} }