3v4l.org

run code in 300+ PHP versions simultaneously
<?php // example to show the magic date 1937-07-01 change in the NL // the Zend\Validate\DateStep does not account for this difference class Blar_DateTime extends DateTime { /** * Return Date in ISO8601 format * * @return String */ public function __toString() { return $this->format('Y-m-d H:i:s'); } /** * Return difference between $this and $now * * @param Datetime|String $now * @return DateInterval */ public function diff($now = 'NOW', $absolute = NULL) { if(!($now instanceOf DateTime)) { $now = new DateTime($now); } return parent::diff($now); } /** * Return Age in Years * * @param Datetime|String $now * @return Integer */ public function getAge($now = 'NOW') { return $this->diff($now)->format('%y'); } } $birthday = new Blar_DateTime('1879-03-14', new DateTimeZone("Europe/Amsterdam")); echo $birthday; echo '<p>In the Netherlands Albert Einstein would now be ', $birthday->diff(new DateTime('NOW', new DateTimeZone("Europe/Amsterdam")))->format('%y Years, %m Months, %d Days, %h Hours, %i Minutes, %s Seconds'), ' old.</p>'; $birthday = new Blar_DateTime('1879-03-14', new DateTimeZone("Europe/London")); echo $birthday; echo '<p>In the United Kingdom Albert Einstein would now be ', $birthday->diff(new DateTime('NOW', new DateTimeZone("Europe/London")))->format('%y Years, %m Months, %d Days, %h Hours, %i Minutes, %s Seconds'), ' old.</p>'; $birthday = new Blar_DateTime('1950-03-14', new DateTimeZone("Europe/Amsterdam")); echo $birthday; echo '<p>the Netherlands mr. Anonymous would now be ', $birthday->diff(new DateTime('NOW', new DateTimeZone("Europe/Amsterdam")))->format('%y Years, %m Months, %d Days, %h Hours, %i Minutes, %s Seconds'), ' old.</p>'; $birthday = new Blar_DateTime('1950-03-14', new DateTimeZone("Europe/London")); echo $birthday; echo '<p>In the mr. Anonymous would now be ', $birthday->diff(new DateTime('NOW', new DateTimeZone("Europe/London")))->format('%y Years, %m Months, %d Days, %h Hours, %i Minutes, %s Seconds'), ' old.</p>'; // output /* 1879-03-14 00:00:00 In the Netherlands Albert Einstein would now be 134 Years, 5 Months, 14 Days, 17 Hours, 54 Minutes, 49 Seconds old. 1879-03-14 00:00:00 In the United Kingdom Albert Einstein would now be 134 Years, 5 Months, 14 Days, 16 Hours, 55 Minutes, 17 Seconds old. 1950-03-14 00:00:00 the Netherlands mr. Anonymous would now be 63 Years, 5 Months, 14 Days, 17 Hours, 55 Minutes, 17 Seconds old. 1950-03-14 00:00:00 In the mr. Anonymous would now be 63 Years, 5 Months, 14 Days, 16 Hours, 55 Minutes, 17 Seconds old. now note the difference in seconds between example 1 and 2 of 28 seconds... exactly the time that does not exists in the netherlands on 1937-07-01 I conclude PHP does it correctly and Zend\Validate\DateStep should account for this. */
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/3iO2j
function name:  (null)
number of ops:  102
compiled vars:  !0 = $birthday
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   DECLARE_CLASS                                            'blar_datetime', 'datetime'
   43     1        NEW                                              $1      'Blar_DateTime'
          2        SEND_VAL_EX                                              '1879-03-14'
          3        NEW                                              $2      'DateTimeZone'
          4        SEND_VAL_EX                                              'Europe%2FAmsterdam'
          5        DO_FCALL                                      0          
          6        SEND_VAR_NO_REF_EX                                       $2
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !0, $1
   45     9        ECHO                                                     !0
   47    10        ECHO                                                     '%3Cp%3EIn+the+Netherlands+Albert+Einstein+would+now+be+'
         11        INIT_METHOD_CALL                                         !0, 'diff'
         12        NEW                                              $6      'DateTime'
         13        SEND_VAL_EX                                              'NOW'
         14        NEW                                              $7      'DateTimeZone'
         15        SEND_VAL_EX                                              'Europe%2FAmsterdam'
         16        DO_FCALL                                      0          
         17        SEND_VAR_NO_REF_EX                                       $7
         18        DO_FCALL                                      0          
         19        SEND_VAR_NO_REF_EX                                       $6
         20        DO_FCALL                                      0  $10     
         21        INIT_METHOD_CALL                                         $10, 'format'
         22        SEND_VAL_EX                                              '%25y+Years%2C+%25m+Months%2C+%25d+Days%2C+%25h+Hours%2C+%25i+Minutes%2C+%25s+Seconds'
         23        DO_FCALL                                      0  $11     
         24        ECHO                                                     $11
         25        ECHO                                                     '+old.%3C%2Fp%3E'
   49    26        NEW                                              $12     'Blar_DateTime'
         27        SEND_VAL_EX                                              '1879-03-14'
         28        NEW                                              $13     'DateTimeZone'
         29        SEND_VAL_EX                                              'Europe%2FLondon'
         30        DO_FCALL                                      0          
         31        SEND_VAR_NO_REF_EX                                       $13
         32        DO_FCALL                                      0          
         33        ASSIGN                                                   !0, $12
   51    34        ECHO                                                     !0
   53    35        ECHO                                                     '%3Cp%3EIn+the+United+Kingdom+Albert+Einstein+would+now+be+'
         36        INIT_METHOD_CALL                                         !0, 'diff'
         37        NEW                                              $17     'DateTime'
         38        SEND_VAL_EX                                              'NOW'
         39        NEW                                              $18     'DateTimeZone'
         40        SEND_VAL_EX                                              'Europe%2FLondon'
         41        DO_FCALL                                      0          
         42        SEND_VAR_NO_REF_EX                                       $18
         43        DO_FCALL                                      0          
         44        SEND_VAR_NO_REF_EX                                       $17
         45        DO_FCALL                                      0  $21     
         46        INIT_METHOD_CALL                                         $21, 'format'
         47        SEND_VAL_EX                                              '%25y+Years%2C+%25m+Months%2C+%25d+Days%2C+%25h+Hours%2C+%25i+Minutes%2C+%25s+Seconds'
         48        DO_FCALL                                      0  $22     
         49        ECHO                                                     $22
         50        ECHO                                                     '+old.%3C%2Fp%3E'
   55    51        NEW                                              $23     'Blar_DateTime'
         52        SEND_VAL_EX                                              '1950-03-14'
         53        NEW                                              $24     'DateTimeZone'
         54        SEND_VAL_EX                                              'Europe%2FAmsterdam'
         55        DO_FCALL                                      0          
         56        SEND_VAR_NO_REF_EX                                       $24
         57        DO_FCALL                                      0          
         58        ASSIGN                                                   !0, $23
   57    59        ECHO                                                     !0
   59    60        ECHO                                                     '%3Cp%3Ethe+Netherlands+mr.+Anonymous+would+now+be+'
         61        INIT_METHOD_CALL                                         !0, 'diff'
         62        NEW                                              $28     'DateTime'
         63        SEND_VAL_EX                                              'NOW'
         64        NEW                                              $29     'DateTimeZone'
         65        SEND_VAL_EX                                              'Europe%2FAmsterdam'
         66        DO_FCALL                                      0          
         67        SEND_VAR_NO_REF_EX                                       $29
         68        DO_FCALL                                      0          
         69        SEND_VAR_NO_REF_EX                                       $28
         70        DO_FCALL                                      0  $32     
         71        INIT_METHOD_CALL                                         $32, 'format'
         72        SEND_VAL_EX                                              '%25y+Years%2C+%25m+Months%2C+%25d+Days%2C+%25h+Hours%2C+%25i+Minutes%2C+%25s+Seconds'
         73        DO_FCALL                                      0  $33     
         74        ECHO                                                     $33
         75        ECHO                                                     '+old.%3C%2Fp%3E'
   61    76        NEW                                              $34     'Blar_DateTime'
         77        SEND_VAL_EX                                              '1950-03-14'
         78        NEW                                              $35     'DateTimeZone'
         79        SEND_VAL_EX                                              'Europe%2FLondon'
         80        DO_FCALL                                      0          
         81        SEND_VAR_NO_REF_EX                                       $35
         82        DO_FCALL                                      0          
         83        ASSIGN                                                   !0, $34
   63    84        ECHO                                                     !0
   65    85        ECHO                                                     '%3Cp%3EIn+the+mr.+Anonymous+would+now+be+'
         86        INIT_METHOD_CALL                                         !0, 'diff'
         87        NEW                                              $39     'DateTime'
         88        SEND_VAL_EX                                              'NOW'
         89        NEW                                              $40     'DateTimeZone'
         90        SEND_VAL_EX                                              'Europe%2FLondon'
         91        DO_FCALL                                      0          
         92        SEND_VAR_NO_REF_EX                                       $40
         93        DO_FCALL                                      0          
         94        SEND_VAR_NO_REF_EX                                       $39
         95        DO_FCALL                                      0  $43     
         96        INIT_METHOD_CALL                                         $43, 'format'
         97        SEND_VAL_EX                                              '%25y+Years%2C+%25m+Months%2C+%25d+Days%2C+%25h+Hours%2C+%25i+Minutes%2C+%25s+Seconds'
         98        DO_FCALL                                      0  $44     
         99        ECHO                                                     $44
        100        ECHO                                                     '+old.%3C%2Fp%3E'
   85   101      > RETURN                                                   1

Class Blar_DateTime:
Function __tostring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/3iO2j
function name:  __toString
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   INIT_METHOD_CALL                                         'format'
          1        SEND_VAL_EX                                              'Y-m-d+H%3Ai%3As'
          2        DO_FCALL                                      0  $0      
          3        VERIFY_RETURN_TYPE                                       $0
          4      > RETURN                                                   $0
   16     5*       VERIFY_RETURN_TYPE                                       
          6*     > RETURN                                                   null

End of function __tostring

Function diff:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 9
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/3iO2j
function name:  diff
number of ops:  14
compiled vars:  !0 = $now, !1 = $absolute
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV_INIT                                        !0      'NOW'
          1        RECV_INIT                                        !1      null
   25     2        INSTANCEOF                                       ~2      !0, 'DateTime'
          3        BOOL_NOT                                         ~3      ~2
          4      > JMPZ                                                     ~3, ->9
   26     5    >   NEW                                              $4      'DateTime'
          6        SEND_VAR_EX                                              !0
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !0, $4
   28     9    >   INIT_STATIC_METHOD_CALL                                  'diff'
         10        SEND_VAR_EX                                              !0
         11        DO_FCALL                                      0  $7      
         12      > RETURN                                                   $7
   29    13*     > RETURN                                                   null

End of function diff

Function getage:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/3iO2j
function name:  getAge
number of ops:  9
compiled vars:  !0 = $now
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   RECV_INIT                                        !0      'NOW'
   38     1        INIT_METHOD_CALL                                         'diff'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $1      
          4        INIT_METHOD_CALL                                         $1, 'format'
          5        SEND_VAL_EX                                              '%25y'
          6        DO_FCALL                                      0  $2      
          7      > RETURN                                                   $2
   39     8*     > RETURN                                                   null

End of function getage

End of class Blar_DateTime.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.81 ms | 1407 KiB | 13 Q