Skip to content
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

Util\Debug: export parent class private attributes and DateTimeImmutable #729

Merged
merged 9 commits into from
Jul 20, 2016

Conversation

Slamdunk
Copy link
Contributor

This patch enhances DateTime export for the new DateTimeImmutable and fixes the behaviour dumping also the private attributes of parent class emulating print_r

@@ -109,10 +109,10 @@ public static function export($var, $maxDepth)
}
} else if ($isObj) {
$return = new \stdclass();
if ($var instanceof \DateTime) {
$return->__CLASS__ = "DateTime";
if ($var instanceof \DateTime || $var instanceof \DateTimeInterface) {
Copy link
Member

Choose a reason for hiding this comment

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

Can actually simply check against DateTimeInterface, since we don't support older PHP versions anymore

@Slamdunk
Copy link
Contributor Author

Changes done.

In the last commit I applied "Replace Nested Conditional with Guard Clauses" pattern: if you don't want such a big change I can revert it (but if you ask me that I'll unfollow you in Twitter)

@Slamdunk
Copy link
Contributor Author

Note: I don't know if I did what you wanted saying "Can you move this block to a private method?", to me it was not strictly necessary, btw done it too.

@Ocramius
Copy link
Member

it was not strictly necessary, btw done it too.

The complexity of the method was starting to become a bit too much: splitting it simplifies things :)

do {
$currentClassName = $reflClass->getName();

foreach ($reflClass->getProperties() as $reflProperty) {
Copy link
Member

@Ocramius Ocramius Jul 20, 2016

Choose a reason for hiding this comment

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

Last test scenario needed (although it's just to prevent regressions):

class A
{
    private $a;
    protected $b;
    public $c;
}

class B extends A
{
    private $a;
    protected $b;
    public $c;
}

The resulting dump of dump(new B) should show following properties, if I'm not mistaken:

  • A#$a
  • B#$a
  • B#$b
  • B#$c

@Ocramius Ocramius self-assigned this Jul 20, 2016
@Ocramius Ocramius added this to the 2.7.0 milestone Jul 20, 2016
@Slamdunk
Copy link
Contributor Author

Indeed there was a bug, fixed :P

@Ocramius Ocramius merged commit 670d814 into doctrine:master Jul 20, 2016
@Ocramius
Copy link
Member

@Slamdunk awesome, thanks!

@Slamdunk Slamdunk deleted the debug-patch branch July 20, 2016 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants