3v4l.org

run code in 300+ PHP versions simultaneously
<?php function scholar_parse_date($date) { if (preg_match('/^\s*(?P<year>\d+)(?>-(?P<month>\d{1,2}))?(?>-(?P<day>\d{1,2}))?\s*$/', $date, $match)) { $y = intval($match['year']); $m = isset($match['month']) ? intval($match['month']) : null; $d = isset($match['day']) ? intval($match['day']) : null; // Jezeli $m jest nullem, tzn. ze $d tez jest nullem, wiec // rok jako liczba calkowita jest poprawny. // Jezeli $m nie jest nullem, musi byc z przedzialu 1..12. // Jezeli $d jest nullem, nic wiecej nie trzeba sprawdzac, // jezeli nie jest, trzeba sprawdzic pelna date. $valid = ((null === $m) || (1 <= $m && $m <= 12)) && ((null === $d) || checkdate($m, $d, $y)); if ($valid) { return array( 'year' => $y, 'month' => $m, 'day' => $d, 'iso' => null === $m ? sprintf('%04d', $y) : (null === $d ? sprintf('%04d-%02d', $y, $m) : sprintf('%04d-%02d-%02d', $y, $m, $d) ), ); } } return false; } var_dump(scholar_parse_date('1992')); var_dump(scholar_parse_date('1992-01')); var_dump(scholar_parse_date('1992-01-04')); var_dump(scholar_parse_date('1992-01-32'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1EBLA
function name:  (null)
number of ops:  25
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'scholar_parse_date'
          2        SEND_VAL                                                 '1992'
          3        DO_FCALL                                      0  $0      
          4        SEND_VAR                                                 $0
          5        DO_ICALL                                                 
   36     6        INIT_FCALL                                               'var_dump'
          7        INIT_FCALL                                               'scholar_parse_date'
          8        SEND_VAL                                                 '1992-01'
          9        DO_FCALL                                      0  $2      
         10        SEND_VAR                                                 $2
         11        DO_ICALL                                                 
   37    12        INIT_FCALL                                               'var_dump'
         13        INIT_FCALL                                               'scholar_parse_date'
         14        SEND_VAL                                                 '1992-01-04'
         15        DO_FCALL                                      0  $4      
         16        SEND_VAR                                                 $4
         17        DO_ICALL                                                 
   38    18        INIT_FCALL                                               'var_dump'
         19        INIT_FCALL                                               'scholar_parse_date'
         20        SEND_VAL                                                 '1992-01-32'
         21        DO_FCALL                                      0  $6      
         22        SEND_VAR                                                 $6
         23        DO_ICALL                                                 
         24      > RETURN                                                   1

Function scholar_parse_date:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 75
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 16
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 24
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
2 jumps found. (Code = 47) Position 1 = 28, Position 2 = 33
Branch analysis from position: 28
2 jumps found. (Code = 46) Position 1 = 30, Position 2 = 32
Branch analysis from position: 30
2 jumps found. (Code = 46) Position 1 = 34, Position 2 = 43
Branch analysis from position: 34
2 jumps found. (Code = 47) Position 1 = 36, Position 2 = 42
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 45, Position 2 = 75
Branch analysis from position: 45
2 jumps found. (Code = 43) Position 1 = 50, Position 2 = 56
Branch analysis from position: 50
1 jumps found. (Code = 42) Position 1 = 73
Branch analysis from position: 73
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 56
2 jumps found. (Code = 43) Position 1 = 58, Position 2 = 65
Branch analysis from position: 58
1 jumps found. (Code = 42) Position 1 = 72
Branch analysis from position: 72
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 65
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 75
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 42
Branch analysis from position: 43
Branch analysis from position: 32
Branch analysis from position: 33
Branch analysis from position: 24
2 jumps found. (Code = 47) Position 1 = 28, Position 2 = 33
Branch analysis from position: 28
Branch analysis from position: 33
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 24
Branch analysis from position: 20
Branch analysis from position: 24
Branch analysis from position: 75
filename:       /in/1EBLA
function name:  scholar_parse_date
number of ops:  77
compiled vars:  !0 = $date, !1 = $match, !2 = $y, !3 = $m, !4 = $d, !5 = $valid
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    4     1        INIT_FCALL                                               'preg_match'
          2        SEND_VAL                                                 '%2F%5E%5Cs%2A%28%3FP%3Cyear%3E%5Cd%2B%29%28%3F%3E-%28%3FP%3Cmonth%3E%5Cd%7B1%2C2%7D%29%29%3F%28%3F%3E-%28%3FP%3Cday%3E%5Cd%7B1%2C2%7D%29%29%3F%5Cs%2A%24%2F'
          3        SEND_VAR                                                 !0
          4        SEND_REF                                                 !1
          5        DO_ICALL                                         $6      
          6      > JMPZ                                                     $6, ->75
    5     7    >   FETCH_DIM_R                                      ~7      !1, 'year'
          8        CAST                                          4  ~8      ~7
          9        ASSIGN                                                   !2, ~8
    6    10        ISSET_ISEMPTY_DIM_OBJ                         0          !1, 'month'
         11      > JMPZ                                                     ~10, ->16
         12    >   FETCH_DIM_R                                      ~11     !1, 'month'
         13        CAST                                          4  ~12     ~11
         14        QM_ASSIGN                                        ~13     ~12
         15      > JMP                                                      ->17
         16    >   QM_ASSIGN                                        ~13     null
         17    >   ASSIGN                                                   !3, ~13
    7    18        ISSET_ISEMPTY_DIM_OBJ                         0          !1, 'day'
         19      > JMPZ                                                     ~15, ->24
         20    >   FETCH_DIM_R                                      ~16     !1, 'day'
         21        CAST                                          4  ~17     ~16
         22        QM_ASSIGN                                        ~18     ~17
         23      > JMP                                                      ->25
         24    >   QM_ASSIGN                                        ~18     null
         25    >   ASSIGN                                                   !4, ~18
   14    26        TYPE_CHECK                                    2  ~20     !3
         27      > JMPNZ_EX                                         ~20     ~20, ->33
         28    >   IS_SMALLER_OR_EQUAL                              ~21     1, !3
         29      > JMPZ_EX                                          ~21     ~21, ->32
         30    >   IS_SMALLER_OR_EQUAL                              ~22     !3, 12
         31        BOOL                                             ~21     ~22
         32    >   BOOL                                             ~20     ~21
         33    > > JMPZ_EX                                          ~20     ~20, ->43
   15    34    >   TYPE_CHECK                                    2  ~23     !4
         35      > JMPNZ_EX                                         ~23     ~23, ->42
         36    >   INIT_FCALL                                               'checkdate'
         37        SEND_VAR                                                 !3
         38        SEND_VAR                                                 !4
         39        SEND_VAR                                                 !2
         40        DO_ICALL                                         $24     
         41        BOOL                                             ~23     $24
         42    >   BOOL                                             ~20     ~23
   14    43    >   ASSIGN                                                   !5, ~20
   17    44      > JMPZ                                                     !5, ->75
   19    45    >   INIT_ARRAY                                       ~26     !2, 'year'
   20    46        ADD_ARRAY_ELEMENT                                ~26     !3, 'month'
   21    47        ADD_ARRAY_ELEMENT                                ~26     !4, 'day'
   22    48        TYPE_CHECK                                    2          !3
         49      > JMPZ                                                     ~27, ->56
   23    50    >   INIT_FCALL                                               'sprintf'
         51        SEND_VAL                                                 '%2504d'
         52        SEND_VAR                                                 !2
         53        DO_ICALL                                         $28     
         54        QM_ASSIGN                                        ~29     $28
         55      > JMP                                                      ->73
   24    56    >   TYPE_CHECK                                    2          !4
         57      > JMPZ                                                     ~30, ->65
   25    58    >   INIT_FCALL                                               'sprintf'
         59        SEND_VAL                                                 '%2504d-%2502d'
         60        SEND_VAR                                                 !2
         61        SEND_VAR                                                 !3
         62        DO_ICALL                                         $31     
         63        QM_ASSIGN                                        ~32     $31
         64      > JMP                                                      ->72
   26    65    >   INIT_FCALL                                               'sprintf'
         66        SEND_VAL                                                 '%2504d-%2502d-%2502d'
         67        SEND_VAR                                                 !2
         68        SEND_VAR                                                 !3
         69        SEND_VAR                                                 !4
         70        DO_ICALL                                         $33     
         71        QM_ASSIGN                                        ~32     $33
         72    >   QM_ASSIGN                                        ~29     ~32
         73    >   ADD_ARRAY_ELEMENT                                ~26     ~29, 'iso'
         74      > RETURN                                                   ~26
   32    75    > > RETURN                                                   <false>
   33    76*     > RETURN                                                   null

End of function scholar_parse_date

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.31 ms | 1407 KiB | 25 Q