DateTimes in variables view

Recently I can't directly view variables of the type datetime in my variables view during debugging.

It just looks like this:

I think that with earlier versions this was different and one saw the date and time in the variables view, but I am not sure. Of course I can find out the date and time by using $lastListTime->format("...") but this is quite tedious to debug if we have a lot of different DateTime variables.

Is this a bug in my case or just a missing feature? Or is there somewhere a configuration where I can configure how a variable of a certain type gets displayed in the variables view (would be great to be able to specify something like a display function ;)).

0

I strongly believe it's never been the case, and this feature is missing not in PhpStorm but in PHP itself - as far as I understand it, Xdebug can only show data that's available via var_dump(), and var_dump() for a DateTime instance returns just what you see in the Variables pane.

0
Avatar
Permanently deleted user

I am not sure if you understood me correctly, in my variables pane I see exactly no information about the DateTime (see the [0] in my screenshot), so I can't open there anything and I was really suprised once during debugging since I thought all my DateTimes are null, this lead me to the assumption that it was different before so that my brain thought automatically this value must be null, but as I said I am not sure.

If I var_dump a DateTime object I get the following:

object(DateTime)#1 (3) {
  ["date"]=>
  string(26) "2020-01-01 00:00:00.000000"
  ["timezone_type"]=>
  int(3)
  ["timezone"]=>
  string(10) "US/Pacific"
}

So this should be enough to display the date and time and maybe even inclusive timezone.

0

I must be missing something then, because I don't get that output from var_dump(): http://prntscr.com/qlqjc1

<?php

$a = new DateTime('now');

var_dump($a);

print $a->format('Y-m-d H:i:s');
print_r($a->getTimezone());

What PHP version are you using?

0
Avatar
Permanently deleted user

Now I get the problem, when testing the var_dump output I was lazy and used an online sandbox (https://3v4l.org/ka1Vg#output), but this sandbox has no xdebug which overrides var_dump. So I think its a problem of xdebug, when I run var_dump() locally on my computer I get

class DateTime#1 (0) {}

which explains the view in phpstorm. But still interesting that I get something different than you get.

I use php 7.4.1 with Xdebug v2.9.0

 

Edit: Found the problem: https://github.com/xdebug/xdebug/pull/536 so there is already an open pull request in the Xdebug repo fixing the problem, but it seems to be a regression from php 7.4, so my intuition was true that this was already better before.

1

Oh wow, great stuff, thank you for sharing!

0

请先登录再写评论。