3v4l.org

run code in 300+ PHP versions simultaneously
<?php class TimeZone { const NO_TIMEZONE = 0; const ASIA_YEKATERINBURG = 310; const EUROPE_KALININGRAD = 390; const EUROPE_MOSCOW = 401; const EUROPE_SAMARA = 409; const ROC = 492; const ROK = 493; const UCT = 494; const UTC = 495; const WET = 496; /** * list of time zones */ public static $constToFullName = array( self::ASIA_YEKATERINBURG => 'Asia/Yekaterinburg', self::EUROPE_KALININGRAD => 'Europe/Kaliningrad', self::EUROPE_MOSCOW => 'Europe/Moscow', self::EUROPE_SAMARA => 'Europe/Samara', ); /** * list of time zones indexed by name */ public static $fullNameToConst = array( 'Europe/Kaliningrad' => self::EUROPE_KALININGRAD, 'Europe/Moscow' => self::EUROPE_MOSCOW, 'Europe/Samara' => self::EUROPE_SAMARA, ); /** * Get time zone string based on constant value * * @param int $const * * @return string|null */ public static function get($const) { if (isset(static::$constToFullName[$const])) { return static::$constToFullName[$const]; } else { return null; } } /** * Get time zone constant value from passed time zone string * * @param int $code * * @return int|null */ public static function findByFullName($code) { if (isset(static::$fullNameToConst[$code])) { return static::$fullNameToConst[$code]; } else { return null; } } /** * Check if constant exists * * @param int $const * * @return bool */ public static function isConst($const) { return isset(static::$constToFullName[$const]); } /** * Get time zone constant value from passed time zone string * * @param string $timeZoneString * * @return bool */ public static function isTimeZone($timeZoneString) { return isset(static::$fullNameToConst[$timeZoneString]); } } const TIME_ZONE_FORMAT_NAME = 'utc'; $TIME_ZONE_FORMAT_NAME = 'utc'; $KEY_VALUE = 'value'; $KEY_NAME = 'name'; $KEY_OFFSET = 'offset'; $KEY_FORMAT = 'format'; $KEY_DISPLAY = 'display'; function convertTimezoneToArray($timezone, $value) { $dateTime = new \DateTime(); $dateTime->setTimeZone(new \DateTimeZone($timezone)); return [ $KEY_VALUE => $value, $KEY_NAME => $timezone, $KEY_OFFSET => $dateTime->format('P'), $KEY_FORMAT => $TIME_ZONE_FORMAT_NAME ]; } function convertTimezoneList(array $timezonesForCountry) { $timezoneArray = []; foreach ($timezonesForCountry as $timeZone) { if (TimeZone::isTimeZone($timeZone)) { $value = TimeZone::findByFullName($timeZone); $timezoneArray[] = convertTimezoneToArray($timeZone, $value); } } return $timezoneArray; } $inputArray = ["Asia/Yekaterinburg", "Europe/Kaliningrad", "Europe/Moscow", "Europe/Samara"]; convertTimezoneList($inputArray);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K9OVU
function name:  (null)
number of ops:  12
compiled vars:  !0 = $TIME_ZONE_FORMAT_NAME, !1 = $KEY_VALUE, !2 = $KEY_NAME, !3 = $KEY_OFFSET, !4 = $KEY_FORMAT, !5 = $KEY_DISPLAY, !6 = $inputArray
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  114     0  E >   DECLARE_CONST                                            'TIME_ZONE_FORMAT_NAME', 'utc'
  115     1        ASSIGN                                                   !0, 'utc'
  116     2        ASSIGN                                                   !1, 'value'
  117     3        ASSIGN                                                   !2, 'name'
  118     4        ASSIGN                                                   !3, 'offset'
  119     5        ASSIGN                                                   !4, 'format'
  120     6        ASSIGN                                                   !5, 'display'
  148     7        ASSIGN                                                   !6, <array>
  149     8        INIT_FCALL                                               'converttimezonelist'
          9        SEND_VAR                                                 !6
         10        DO_FCALL                                      0          
         11      > RETURN                                                   1

Function converttimezonetoarray:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K9OVU
function name:  convertTimezoneToArray
number of ops:  20
compiled vars:  !0 = $timezone, !1 = $value, !2 = $dateTime, !3 = $KEY_VALUE, !4 = $KEY_NAME, !5 = $KEY_OFFSET, !6 = $KEY_FORMAT, !7 = $TIME_ZONE_FORMAT_NAME
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  121     0  E >   RECV                                             !0      
          1        RECV                                             !1      
  123     2        NEW                                              $8      'DateTime'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !2, $8
  124     5        INIT_METHOD_CALL                                         !2, 'setTimeZone'
          6        NEW                                              $11     'DateTimeZone'
          7        SEND_VAR_EX                                              !0
          8        DO_FCALL                                      0          
          9        SEND_VAR_NO_REF_EX                                       $11
         10        DO_FCALL                                      0          
  127    11        INIT_ARRAY                                       ~14     !1, !3
  128    12        ADD_ARRAY_ELEMENT                                ~14     !0, !4
  129    13        INIT_METHOD_CALL                                         !2, 'format'
         14        SEND_VAL_EX                                              'P'
         15        DO_FCALL                                      0  $15     
         16        ADD_ARRAY_ELEMENT                                ~14     $15, !5
  130    17        ADD_ARRAY_ELEMENT                                ~14     !7, !6
         18      > RETURN                                                   ~14
  132    19*     > RETURN                                                   null

End of function converttimezonetoarray

Function converttimezonelist:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 19
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 19
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 18
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 18
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/K9OVU
function name:  convertTimezoneList
number of ops:  22
compiled vars:  !0 = $timezonesForCountry, !1 = $timezoneArray, !2 = $timeZone, !3 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  133     0  E >   RECV                                             !0      
  135     1        ASSIGN                                                   !1, <array>
  137     2      > FE_RESET_R                                       $5      !0, ->19
          3    > > FE_FETCH_R                                               $5, !2, ->19
  138     4    >   INIT_STATIC_METHOD_CALL                                  'TimeZone', 'isTimeZone'
          5        SEND_VAR                                                 !2
          6        DO_FCALL                                      0  $6      
          7      > JMPZ                                                     $6, ->18
  139     8    >   INIT_STATIC_METHOD_CALL                                  'TimeZone', 'findByFullName'
          9        SEND_VAR                                                 !2
         10        DO_FCALL                                      0  $7      
         11        ASSIGN                                                   !3, $7
  141    12        INIT_FCALL                                               'converttimezonetoarray'
         13        SEND_VAR                                                 !2
         14        SEND_VAR                                                 !3
         15        DO_FCALL                                      0  $10     
         16        ASSIGN_DIM                                               !1
         17        OP_DATA                                                  $10
  137    18    > > JMP                                                      ->3
         19    >   FE_FREE                                                  $5
  145    20      > RETURN                                                   !1
  146    21*     > RETURN                                                   null

End of function converttimezonelist

Class TimeZone:
Function get:
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
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K9OVU
function name:  get
number of ops:  10
compiled vars:  !0 = $const
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   63     0  E >   RECV                                             !0      
   65     1        FETCH_STATIC_PROP_IS                             ~1      'constToFullName'
          2        ISSET_ISEMPTY_DIM_OBJ                         0          ~1, !0
          3      > JMPZ                                                     ~2, ->8
   66     4    >   FETCH_STATIC_PROP_R          unknown             ~3      'constToFullName'
          5        FETCH_DIM_R                                      ~4      ~3, !0
          6      > RETURN                                                   ~4
          7*       JMP                                                      ->9
   68     8    > > RETURN                                                   null
   70     9*     > RETURN                                                   null

End of function get

Function findbyfullname:
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
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K9OVU
function name:  findByFullName
number of ops:  10
compiled vars:  !0 = $code
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   79     0  E >   RECV                                             !0      
   81     1        FETCH_STATIC_PROP_IS                             ~1      'fullNameToConst'
          2        ISSET_ISEMPTY_DIM_OBJ                         0          ~1, !0
          3      > JMPZ                                                     ~2, ->8
   82     4    >   FETCH_STATIC_PROP_R          unknown             ~3      'fullNameToConst'
          5        FETCH_DIM_R                                      ~4      ~3, !0
          6      > RETURN                                                   ~4
          7*       JMP                                                      ->9
   84     8    > > RETURN                                                   null
   86     9*     > RETURN                                                   null

End of function findbyfullname

Function isconst:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K9OVU
function name:  isConst
number of ops:  5
compiled vars:  !0 = $const
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   96     0  E >   RECV                                             !0      
   98     1        FETCH_STATIC_PROP_IS                             ~1      'constToFullName'
          2        ISSET_ISEMPTY_DIM_OBJ                         0  ~2      ~1, !0
          3      > RETURN                                                   ~2
   99     4*     > RETURN                                                   null

End of function isconst

Function istimezone:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K9OVU
function name:  isTimeZone
number of ops:  5
compiled vars:  !0 = $timeZoneString
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  108     0  E >   RECV                                             !0      
  110     1        FETCH_STATIC_PROP_IS                             ~1      'fullNameToConst'
          2        ISSET_ISEMPTY_DIM_OBJ                         0  ~2      ~1, !0
          3      > RETURN                                                   ~2
  111     4*     > RETURN                                                   null

End of function istimezone

End of class TimeZone.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
168.96 ms | 1407 KiB | 15 Q