3v4l.org

run code in 300+ PHP versions simultaneously
<?php function munge( $s ) { $segments = preg_split( '/([{}])/', $s, -1, PREG_SPLIT_DELIM_CAPTURE ); $level = 0; for ( $i = 0, $len = count( $segments ); $i < $len; $i++ ) { if ( $level === 0 && str_starts_with( $segments[$i], 'O:10:"DatePeriod":' ) ) { $level = 1; $dp_header_index = $i; $i++; // consume opening '{' of DatePeriod object $has_include_end_date = false; } elseif ( $level ) { if ( $segments[$i] === '{' ) { $level++; } elseif ( $segments[$i] === '}' ) { $level--; if ( !$level ) { // end of DatePeriod object if( !$has_include_end_date ) { // append 'include_end_date' property $segments[$i] = 's:16:"include_end_date";b:0;}'; // adjust object header $dp_header = $segments[$dp_header_index]; $dp_header_parts = explode( ':', $dp_header ); // 'O', class name length, class name, # of props $dp_header_parts[3] += 1; $dp_header = implode( ':', $dp_header_parts ); $segments[$dp_header_index] = $dp_header; } } } elseif ( $level === 1 ) { if ( preg_match( '/(^|;)s:16:"include_end_date";b:/', $segments[$i] ) ) { // serialization was generated in PHP 8.2+ $has_include_end_date = true; } } else { // Nested object inside DatePeriod, ignore. A DatePeriod can't contain another DatePeriod. } } } return implode( $segments ); } $php81_dp = 'O:10:"DatePeriod":6:{s:5:"start";O:8:"DateTime":3:{s:4:"date";s:26:"2025-10-15 16:50:00.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:16:"Europe/Amsterdam";}s:7:"current";N;s:3:"end";N;s:8:"interval";O:12:"DateInterval":16:{s:1:"y";i:0;s:1:"m";i:0;s:1:"d";i:1;s:1:"h";i:0;s:1:"i";i:0;s:1:"s";i:0;s:1:"f";d:0;s:7:"weekday";i:0;s:16:"weekday_behavior";i:0;s:17:"first_last_day_of";i:0;s:6:"invert";i:0;s:4:"days";b:0;s:12:"special_type";i:0;s:14:"special_amount";i:0;s:21:"have_weekday_relative";i:0;s:21:"have_special_relative";i:0;}s:11:"recurrences";i:4;s:18:"include_start_date";b:1;}'; $php83_dp = 'O:10:"DatePeriod":7:{s:5:"start";O:8:"DateTime":3:{s:4:"date";s:26:"2025-10-15 16:50:00.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:16:"Europe/Amsterdam";}s:7:"current";N;s:3:"end";N;s:8:"interval";O:12:"DateInterval":10:{s:1:"y";i:0;s:1:"m";i:0;s:1:"d";i:1;s:1:"h";i:0;s:1:"i";i:0;s:1:"s";i:0;s:1:"f";d:0;s:6:"invert";i:0;s:4:"days";b:0;s:11:"from_string";b:0;}s:11:"recurrences";i:4;s:18:"include_start_date";b:1;s:16:"include_end_date";b:0;}'; var_dump( munge( $php81_dp ) ); var_dump( munge( $php83_dp ) ); var_dump( unserialize( munge( $php81_dp ) ) ); var_dump( unserialize( munge( $php83_dp ) ) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HHYIQ
function name:  (null)
number of ops:  33
compiled vars:  !0 = $php81_dp, !1 = $php83_dp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   ASSIGN                                                   !0, 'O%3A10%3A%22DatePeriod%22%3A6%3A%7Bs%3A5%3A%22start%22%3BO%3A8%3A%22DateTime%22%3A3%3A%7Bs%3A4%3A%22date%22%3Bs%3A26%3A%222025-10-15+16%3A50%3A00.000000%22%3Bs%3A13%3A%22timezone_type%22%3Bi%3A3%3Bs%3A8%3A%22timezone%22%3Bs%3A16%3A%22Europe%2FAmsterdam%22%3B%7Ds%3A7%3A%22current%22%3BN%3Bs%3A3%3A%22end%22%3BN%3Bs%3A8%3A%22interval%22%3BO%3A12%3A%22DateInterval%22%3A16%3A%7Bs%3A1%3A%22y%22%3Bi%3A0%3Bs%3A1%3A%22m%22%3Bi%3A0%3Bs%3A1%3A%22d%22%3Bi%3A1%3Bs%3A1%3A%22h%22%3Bi%3A0%3Bs%3A1%3A%22i%22%3Bi%3A0%3Bs%3A1%3A%22s%22%3Bi%3A0%3Bs%3A1%3A%22f%22%3Bd%3A0%3Bs%3A7%3A%22weekday%22%3Bi%3A0%3Bs%3A16%3A%22weekday_behavior%22%3Bi%3A0%3Bs%3A17%3A%22first_last_day_of%22%3Bi%3A0%3Bs%3A6%3A%22invert%22%3Bi%3A0%3Bs%3A4%3A%22days%22%3Bb%3A0%3Bs%3A12%3A%22special_type%22%3Bi%3A0%3Bs%3A14%3A%22special_amount%22%3Bi%3A0%3Bs%3A21%3A%22have_weekday_relative%22%3Bi%3A0%3Bs%3A21%3A%22have_special_relative%22%3Bi%3A0%3B%7Ds%3A11%3A%22recurrences%22%3Bi%3A4%3Bs%3A18%3A%22include_start_date%22%3Bb%3A1%3B%7D'
   48     1        ASSIGN                                                   !1, 'O%3A10%3A%22DatePeriod%22%3A7%3A%7Bs%3A5%3A%22start%22%3BO%3A8%3A%22DateTime%22%3A3%3A%7Bs%3A4%3A%22date%22%3Bs%3A26%3A%222025-10-15+16%3A50%3A00.000000%22%3Bs%3A13%3A%22timezone_type%22%3Bi%3A3%3Bs%3A8%3A%22timezone%22%3Bs%3A16%3A%22Europe%2FAmsterdam%22%3B%7Ds%3A7%3A%22current%22%3BN%3Bs%3A3%3A%22end%22%3BN%3Bs%3A8%3A%22interval%22%3BO%3A12%3A%22DateInterval%22%3A10%3A%7Bs%3A1%3A%22y%22%3Bi%3A0%3Bs%3A1%3A%22m%22%3Bi%3A0%3Bs%3A1%3A%22d%22%3Bi%3A1%3Bs%3A1%3A%22h%22%3Bi%3A0%3Bs%3A1%3A%22i%22%3Bi%3A0%3Bs%3A1%3A%22s%22%3Bi%3A0%3Bs%3A1%3A%22f%22%3Bd%3A0%3Bs%3A6%3A%22invert%22%3Bi%3A0%3Bs%3A4%3A%22days%22%3Bb%3A0%3Bs%3A11%3A%22from_string%22%3Bb%3A0%3B%7Ds%3A11%3A%22recurrences%22%3Bi%3A4%3Bs%3A18%3A%22include_start_date%22%3Bb%3A1%3Bs%3A16%3A%22include_end_date%22%3Bb%3A0%3B%7D'
   50     2        INIT_FCALL                                               'var_dump'
          3        INIT_FCALL                                               'munge'
          4        SEND_VAR                                                 !0
          5        DO_FCALL                                      0  $4      
          6        SEND_VAR                                                 $4
          7        DO_ICALL                                                 
   51     8        INIT_FCALL                                               'var_dump'
          9        INIT_FCALL                                               'munge'
         10        SEND_VAR                                                 !1
         11        DO_FCALL                                      0  $6      
         12        SEND_VAR                                                 $6
         13        DO_ICALL                                                 
   53    14        INIT_FCALL                                               'var_dump'
         15        INIT_FCALL                                               'unserialize'
         16        INIT_FCALL                                               'munge'
         17        SEND_VAR                                                 !0
         18        DO_FCALL                                      0  $8      
         19        SEND_VAR                                                 $8
         20        DO_ICALL                                         $9      
         21        SEND_VAR                                                 $9
         22        DO_ICALL                                                 
   54    23        INIT_FCALL                                               'var_dump'
         24        INIT_FCALL                                               'unserialize'
         25        INIT_FCALL                                               'munge'
         26        SEND_VAR                                                 !1
         27        DO_FCALL                                      0  $11     
         28        SEND_VAR                                                 $11
         29        DO_ICALL                                         $12     
         30        SEND_VAR                                                 $12
         31        DO_ICALL                                                 
         32      > RETURN                                                   1

Function munge:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 71
Branch analysis from position: 71
2 jumps found. (Code = 44) Position 1 = 73, Position 2 = 13
Branch analysis from position: 73
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
2 jumps found. (Code = 46) Position 1 = 15, Position 2 = 21
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 27
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 70
Branch analysis from position: 70
2 jumps found. (Code = 44) Position 1 = 73, Position 2 = 13
Branch analysis from position: 73
Branch analysis from position: 13
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 70
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 33
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 70
Branch analysis from position: 70
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 60
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 59
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 59
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 70
Branch analysis from position: 70
Branch analysis from position: 59
Branch analysis from position: 59
Branch analysis from position: 60
2 jumps found. (Code = 43) Position 1 = 62, Position 2 = 70
Branch analysis from position: 62
2 jumps found. (Code = 43) Position 1 = 68, Position 2 = 69
Branch analysis from position: 68
1 jumps found. (Code = 42) Position 1 = 70
Branch analysis from position: 70
Branch analysis from position: 69
Branch analysis from position: 70
Branch analysis from position: 70
Branch analysis from position: 21
filename:       /in/HHYIQ
function name:  munge
number of ops:  78
compiled vars:  !0 = $s, !1 = $segments, !2 = $level, !3 = $i, !4 = $len, !5 = $dp_header_index, !6 = $has_include_end_date, !7 = $dp_header, !8 = $dp_header_parts
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        INIT_FCALL                                               'preg_split'
          2        SEND_VAL                                                 '%2F%28%5B%7B%7D%5D%29%2F'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 -1
          5        SEND_VAL                                                 2
          6        DO_ICALL                                         $9      
          7        ASSIGN                                                   !1, $9
    5     8        ASSIGN                                                   !2, 0
    7     9        ASSIGN                                                   !3, 0
         10        COUNT                                            ~13     !1
         11        ASSIGN                                                   !4, ~13
         12      > JMP                                                      ->71
    8    13    >   IS_IDENTICAL                                     ~15     !2, 0
         14      > JMPZ_EX                                          ~15     ~15, ->21
    9    15    >   INIT_FCALL                                               'str_starts_with'
         16        FETCH_DIM_R                                      ~16     !1, !3
         17        SEND_VAL                                                 ~16
         18        SEND_VAL                                                 'O%3A10%3A%22DatePeriod%22%3A'
         19        DO_ICALL                                         $17     
         20        BOOL                                             ~15     $17
         21    > > JMPZ                                                     ~15, ->27
   11    22    >   ASSIGN                                                   !2, 1
   12    23        ASSIGN                                                   !5, !3
   13    24        PRE_INC                                                  !3
   14    25        ASSIGN                                                   !6, <false>
    8    26      > JMP                                                      ->70
   15    27    > > JMPZ                                                     !2, ->70
   16    28    >   FETCH_DIM_R                                      ~22     !1, !3
         29        IS_IDENTICAL                                             ~22, '%7B'
         30      > JMPZ                                                     ~23, ->33
   17    31    >   PRE_INC                                                  !2
   16    32      > JMP                                                      ->70
   18    33    >   FETCH_DIM_R                                      ~25     !1, !3
         34        IS_IDENTICAL                                             ~25, '%7D'
         35      > JMPZ                                                     ~26, ->60
   19    36    >   PRE_DEC                                                  !2
   20    37        BOOL_NOT                                         ~28     !2
         38      > JMPZ                                                     ~28, ->59
   21    39    >   BOOL_NOT                                         ~29     !6
         40      > JMPZ                                                     ~29, ->59
   23    41    >   ASSIGN_DIM                                               !1, !3
         42        OP_DATA                                                  's%3A16%3A%22include_end_date%22%3Bb%3A0%3B%7D'
   26    43        FETCH_DIM_R                                      ~31     !1, !5
         44        ASSIGN                                                   !7, ~31
   27    45        INIT_FCALL                                               'explode'
         46        SEND_VAL                                                 '%3A'
         47        SEND_VAR                                                 !7
         48        DO_ICALL                                         $33     
         49        ASSIGN                                                   !8, $33
   28    50        ASSIGN_DIM_OP                +=               1          !8, 3
         51        OP_DATA                                                  1
   29    52        INIT_FCALL                                               'implode'
         53        SEND_VAL                                                 '%3A'
         54        SEND_VAR                                                 !8
         55        DO_ICALL                                         $36     
         56        ASSIGN                                                   !7, $36
   30    57        ASSIGN_DIM                                               !1, !5
         58        OP_DATA                                                  !7
   18    59    > > JMP                                                      ->70
   33    60    >   IS_IDENTICAL                                             !2, 1
         61      > JMPZ                                                     ~39, ->70
   34    62    >   INIT_FCALL                                               'preg_match'
         63        SEND_VAL                                                 '%2F%28%5E%7C%3B%29s%3A16%3A%22include_end_date%22%3Bb%3A%2F'
         64        FETCH_DIM_R                                      ~40     !1, !3
         65        SEND_VAL                                                 ~40
         66        DO_ICALL                                         $41     
         67      > JMPZ                                                     $41, ->69
   36    68    >   ASSIGN                                                   !6, <true>
   33    69    > > JMP                                                      ->70
    7    70    >   PRE_INC                                                  !3
         71    >   IS_SMALLER                                               !3, !4
         72      > JMPNZ                                                    ~44, ->13
   44    73    >   INIT_FCALL                                               'implode'
         74        SEND_VAR                                                 !1
         75        DO_ICALL                                         $45     
         76      > RETURN                                                   $45
   45    77*     > RETURN                                                   null

End of function munge

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.63 ms | 1037 KiB | 24 Q