3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Blar_DateTime extends DateTime { /** * Return Date in ISO8601 format * * @return String */ public function __toString() { return $this->format('Y-m-d H:i'); } /** * Return difference between $this and $now * * @param Datetime|String $now * @return DateInterval */ public function diff($now = 'NOW') { 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'); // Example 1 echo $birthday; // Result: 1879-03-14 00:00 // Example 2 echo '<p>Albert Einstein would now be ', $birthday->getAge(), ' years old.</p>'; // Result: <p>Albert Einstein would now be 130 years old.</p> // Example 3 echo '<p>Albert Einstein would now be ', $birthday->diff()->format('%y Years, %m Months, %d Days'), ' old.</p>'; // Result: <p>Albert Einstein would now be 130 Years, 10 Months, 10 Days old.</p> // Example 4 echo '<p>Albert Einstein was on 2010-10-10 ', $birthday->getAge('2010-10-10'), ' years old.</p>'; // Result: <p>Albert Einstein was on 2010-10-10 131 years old.</p>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WXoa8
function name:  (null)
number of ops:  26
compiled vars:  !0 = $birthday
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                            'blar_datetime', 'datetime'
   39     1        NEW                                              $1      'Blar_DateTime'
          2        SEND_VAL_EX                                              '1879-03-14'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $1
   42     5        ECHO                                                     !0
   46     6        ECHO                                                     '%3Cp%3EAlbert+Einstein+would+now+be+'
          7        INIT_METHOD_CALL                                         !0, 'getAge'
          8        DO_FCALL                                      0  $4      
          9        ECHO                                                     $4
         10        ECHO                                                     '+years+old.%3C%2Fp%3E'
   50    11        ECHO                                                     '%3Cp%3EAlbert+Einstein+would+now+be+'
         12        INIT_METHOD_CALL                                         !0, 'diff'
         13        DO_FCALL                                      0  $5      
         14        INIT_METHOD_CALL                                         $5, 'format'
         15        SEND_VAL_EX                                              '%25y+Years%2C+%25m+Months%2C+%25d+Days'
         16        DO_FCALL                                      0  $6      
         17        ECHO                                                     $6
         18        ECHO                                                     '+old.%3C%2Fp%3E'
   54    19        ECHO                                                     '%3Cp%3EAlbert+Einstein+was+on+2010-10-10+'
         20        INIT_METHOD_CALL                                         !0, 'getAge'
         21        SEND_VAL_EX                                              '2010-10-10'
         22        DO_FCALL                                      0  $7      
         23        ECHO                                                     $7
         24        ECHO                                                     '+years+old.%3C%2Fp%3E'
   55    25      > 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/WXoa8
function name:  __toString
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   INIT_METHOD_CALL                                         'format'
          1        SEND_VAL_EX                                              'Y-m-d+H%3Ai'
          2        DO_FCALL                                      0  $0      
          3        VERIFY_RETURN_TYPE                                       $0
          4      > RETURN                                                   $0
   12     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 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/WXoa8
function name:  diff
number of ops:  13
compiled vars:  !0 = $now
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV_INIT                                        !0      'NOW'
   21     1        INSTANCEOF                                       ~1      !0, 'DateTime'
          2        BOOL_NOT                                         ~2      ~1
          3      > JMPZ                                                     ~2, ->8
   22     4    >   NEW                                              $3      'DateTime'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !0, $3
   24     8    >   INIT_STATIC_METHOD_CALL                                  'diff'
          9        SEND_VAR_EX                                              !0
         10        DO_FCALL                                      0  $6      
         11      > RETURN                                                   $6
   25    12*     > 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/WXoa8
function name:  getAge
number of ops:  9
compiled vars:  !0 = $now
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV_INIT                                        !0      'NOW'
   34     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
   35     8*     > RETURN                                                   null

End of function getage

End of class Blar_DateTime.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.14 ms | 1399 KiB | 13 Q