Skip to content

[VarExporter] fix dumping protected property from abstract classes #29418

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
Dec 2, 2018
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
3 changes: 1 addition & 2 deletions src/Symfony/Component/VarExporter/Internal/Exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ public static function prepare($values, $objectsPool, &$refsPool, &$objectsCount
$c = 'stdClass';
} elseif ('*' === $n[1]) {
$n = substr($n, 3);
$c = $reflector->getProperty($n)->class;
if ('Error' === $c) {
if ('Error' === $c = $class) {
$c = 'TypeError';
} elseif ('Exception' === $c) {
$c = 'ErrorException';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
$o = [
clone (\Symfony\Component\VarExporter\Internal\Registry::$prototypes['Symfony\\Component\\VarExporter\\Tests\\ConcreteClass'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('Symfony\\Component\\VarExporter\\Tests\\ConcreteClass')),
],
null,
[
'Symfony\\Component\\VarExporter\\Tests\\ConcreteClass' => [
'foo' => [
123,
],
],
],
$o[0],
[]
);
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
]),
null,
[
'TypeError' => [
'Symfony\\Component\\VarExporter\\Tests\\FinalError' => [
'file' => [
\dirname(__DIR__).\DIRECTORY_SEPARATOR.'VarExporterTest.php',
],
Expand Down
6 changes: 5 additions & 1 deletion src/Symfony/Component/VarExporter/Tests/Fixtures/private.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@
'Symfony\\Component\\VarExporter\\Tests\\MyPrivateValue' => [
'prot' => [
123,
123,
],
'priv' => [
234,
234,
],
],
'Symfony\\Component\\VarExporter\\Tests\\MyPrivateChildValue' => [
'prot' => [
1 => 123,
],
],
],
[
$o[0],
Expand Down
15 changes: 15 additions & 0 deletions src/Symfony/Component/VarExporter/Tests/VarExporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ public function provideExport()
$value->bis = new \ReflectionClass($value);

yield array('wakeup-refl', $value);

yield array('abstract-parent', new ConcreteClass());
}
}

Expand Down Expand Up @@ -320,3 +322,16 @@ public function __clone()
throw new \BadMethodCallException('Should not be called.');
}
}

abstract class AbstractClass
{
protected $foo;
}

class ConcreteClass extends AbstractClass
{
public function __construct()
{
$this->foo = 123;
}
}