2

When I var_dump a DateInterval object, as in this example from the PHP documentation:

$interval = new DateInterval('P2Y4DT6H8M');
var_dump($interval);

I see several properties that are not described in the manual.

PHP Manual                        My var_dump
----------------------------      ------------------------------------------
object(DateInterval)#1 (8) {      object(DateInterval)[1]
  ["y"]=> int(2)                    public 'y' => int(2)
  ["m"]=> int(0)                    public 'm' => int(0)
  ["d"]=> int(4)                    public 'd' => int(4)
  ["h"]=> int(6)                    public 'h' => int(6)
  ["i"]=> int(8)                    public 'i' => int(8)
  ["s"]=> int(0)                    public 's' => int(0)
                                    public 'weekday' => int 0
                                    public 'weekday_behavior' => int 0
                                    public 'first_last_day_of' => int 0
  ["invert"]=> int(0)               public 'invert' => int 0
  ["days"]=> bool(false)            public 'days' => boolean false
                                    public 'special_type' => int 0
                                    public 'special_amount' => int 0
                                    public 'have_weekday_relative' => int 0
                                    public 'have_special_relative' => int 0
}

I thought it might be a difference between PHP versions, so I ran it at 3v4l.org and it looks kind of inconsistent as to which older PHP versions produce which output (various 5.3 and 5.4 versions produce one or the other).

I would like to know what 'have_special_relative' etc. are and what they are intended to be used for, but I have not had much luck with my googling so far. I've also experimented with quite a few different intervals and have not been able to make any of the unknown properties != 0.

Can someone point me in the right direction to figure this out?

Don't Panic
  • 41,125
  • 10
  • 61
  • 80
  • Whilst this might not seem like a duplicate at first glance, the same thing is going on here as in the linked question. The answers there give adequate explanation without repeating the effort here. I hope that helps you. – vascowhite Jul 22 '16 at 13:23
  • @vascowhite Absolutely, thanks. That certainly does explain why I see them. Although, I still wonder why they only show up in certain versions. – Don't Panic Jul 22 '16 at 13:37
  • Changes to PHP internals I imagine :) – vascowhite Jul 22 '16 at 13:38
  • I am running it on php7.2.1 and getting the list of unlisted properties, as mentioned in the question. However, as mentioned in the answers for duplicate questions, I am able to access all these properties. I am unable to find a good explanation to what these properties are for. – Annapurna May 29 '19 at 15:28

0 Answers0