3v4l.org

run code in 300+ PHP versions simultaneously
<?php date_default_timezone_set('America/New_York'); function date_to_unix($date){ $date = DateTime::createFromFormat('Ymd', $date); return $date->getTimestamp(); } function unix_to_date($unix){ $date = DateTime::createFromFormat('U', $unix); $date->setTimezone(new \DateTimeZone(date_default_timezone_get())); return $date->format('Ymd'); } $originalDate = '20140525'; $timeStamp = date_to_unix($originalDate); $newDate = unix_to_date($timeStamp); echo "$originalDate gives a timestamp of $timeStamp which converts back to $newDate";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vD5ll
function name:  (null)
number of ops:  19
compiled vars:  !0 = $originalDate, !1 = $timeStamp, !2 = $newDate
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   INIT_FCALL                                               'date_default_timezone_set'
          1        SEND_VAL                                                 'America%2FNew_York'
          2        DO_ICALL                                                 
   15     3        ASSIGN                                                   !0, '20140525'
   16     4        INIT_FCALL                                               'date_to_unix'
          5        SEND_VAR                                                 !0
          6        DO_FCALL                                      0  $5      
          7        ASSIGN                                                   !1, $5
   17     8        INIT_FCALL                                               'unix_to_date'
          9        SEND_VAR                                                 !1
         10        DO_FCALL                                      0  $7      
         11        ASSIGN                                                   !2, $7
   19    12        ROPE_INIT                                     5  ~10     !0
         13        ROPE_ADD                                      1  ~10     ~10, '+gives+a+timestamp+of+'
         14        ROPE_ADD                                      2  ~10     ~10, !1
         15        ROPE_ADD                                      3  ~10     ~10, '+which+converts+back+to+'
         16        ROPE_END                                      4  ~9      ~10, !2
         17        ECHO                                                     ~9
         18      > RETURN                                                   1

Function date_to_unix:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vD5ll
function name:  date_to_unix
number of ops:  10
compiled vars:  !0 = $date
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    5     1        INIT_STATIC_METHOD_CALL                                  'DateTime', 'createFromFormat'
          2        SEND_VAL                                                 'Ymd'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $1      
          5        ASSIGN                                                   !0, $1
    6     6        INIT_METHOD_CALL                                         !0, 'getTimestamp'
          7        DO_FCALL                                      0  $3      
          8      > RETURN                                                   $3
    7     9*     > RETURN                                                   null

End of function date_to_unix

Function unix_to_date:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vD5ll
function name:  unix_to_date
number of ops:  19
compiled vars:  !0 = $unix, !1 = $date
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   10     1        INIT_STATIC_METHOD_CALL                                  'DateTime', 'createFromFormat'
          2        SEND_VAL                                                 'U'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $2      
          5        ASSIGN                                                   !1, $2
   11     6        INIT_METHOD_CALL                                         !1, 'setTimezone'
          7        NEW                                              $4      'DateTimeZone'
          8        INIT_FCALL                                               'date_default_timezone_get'
          9        DO_ICALL                                         $5      
         10        SEND_VAR_NO_REF_EX                                       $5
         11        DO_FCALL                                      0          
         12        SEND_VAR_NO_REF_EX                                       $4
         13        DO_FCALL                                      0          
   12    14        INIT_METHOD_CALL                                         !1, 'format'
         15        SEND_VAL_EX                                              'Ymd'
         16        DO_FCALL                                      0  $8      
         17      > RETURN                                                   $8
   13    18*     > RETURN                                                   null

End of function unix_to_date

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.66 ms | 1403 KiB | 19 Q