3v4l.org

run code in 500+ 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 = 62
Branch analysis from position: 62
2 jumps found. (Code = 44) Position 1 = 64, Position 2 = 13
Branch analysis from position: 64
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
2 jumps found. (Code = 46) Position 1 = 15, Position 2 = 18
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 24
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 61
Branch analysis from position: 61
2 jumps found. (Code = 44) Position 1 = 64, Position 2 = 13
Branch analysis from position: 64
Branch analysis from position: 13
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 61
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 30
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 61
Branch analysis from position: 61
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 54
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 53
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 53
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 61
Branch analysis from position: 61
Branch analysis from position: 53
Branch analysis from position: 53
Branch analysis from position: 54
2 jumps found. (Code = 43) Position 1 = 56, Position 2 = 61
Branch analysis from position: 56
2 jumps found. (Code = 43) Position 1 = 59, Position 2 = 60
Branch analysis from position: 59
1 jumps found. (Code = 42) Position 1 = 61
Branch analysis from position: 61
Branch analysis from position: 60
Branch analysis from position: 61
Branch analysis from position: 61
Branch analysis from position: 18
filename:       /in/HHYIQ
function name:  munge
number of ops:  67
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                                                          ->62
    8    13    >   IS_IDENTICAL                                         ~15     !2, 0
         14      > JMPZ_EX                                              ~15     ~15, ->18
    9    15    >   FETCH_DIM_R                                          ~16     !1, !3
         16        FRAMELESS_ICALL_2                str_starts_with      ~17     ~16, 'O%3A10%3A%22DatePeriod%22%3A'
         17        BOOL                                                 ~15     ~17
         18    > > JMPZ                                                         ~15, ->24
   11    19    >   ASSIGN                                                       !2, 1
   12    20        ASSIGN                                                       !5, !3
   13    21        PRE_INC                                                      !3
   14    22        ASSIGN                                                       !6, <false>
    8    23      > JMP                                                          ->61
   15    24    > > JMPZ                                                         !2, ->61
   16    25    >   FETCH_DIM_R                                          ~22     !1, !3
         26        IS_IDENTICAL                                                 ~22, '%7B'
         27      > JMPZ                                                         ~23, ->30
   17    28    >   PRE_INC                                                      !2
   16    29      > JMP                                                          ->61
   18    30    >   FETCH_DIM_R                                          ~25     !1, !3
         31        IS_IDENTICAL                                                 ~25, '%7D'
         32      > JMPZ                                                         ~26, ->54
   19    33    >   PRE_DEC                                                      !2
   20    34        BOOL_NOT                                             ~28     !2
         35      > JMPZ                                                         ~28, ->53
   21    36    >   BOOL_NOT                                             ~29     !6
         37      > JMPZ                                                         ~29, ->53
   23    38    >   ASSIGN_DIM                                                   !1, !3
         39        OP_DATA                                                      's%3A16%3A%22include_end_date%22%3Bb%3A0%3B%7D'
   26    40        FETCH_DIM_R                                          ~31     !1, !5
         41        ASSIGN                                                       !7, ~31
   27    42        INIT_FCALL                                                   'explode'
         43        SEND_VAL                                                     '%3A'
         44        SEND_VAR                                                     !7
         45        DO_ICALL                                             $33     
         46        ASSIGN                                                       !8, $33
   28    47        ASSIGN_DIM_OP                    +=               1          !8, 3
         48        OP_DATA                                                      1
   29    49        FRAMELESS_ICALL_2                implode             ~36     '%3A', !8
         50        ASSIGN                                                       !7, ~36
   30    51        ASSIGN_DIM                                                   !1, !5
         52        OP_DATA                                                      !7
   18    53    > > JMP                                                          ->61
   33    54    >   IS_IDENTICAL                                                 !2, 1
         55      > JMPZ                                                         ~39, ->61
   34    56    >   FETCH_DIM_R                                          ~40     !1, !3
         57        FRAMELESS_ICALL_2                preg_match          ~41     '%2F%28%5E%7C%3B%29s%3A16%3A%22include_end_date%22%3Bb%3A%2F', ~40
         58      > JMPZ                                                         ~41, ->60
   36    59    >   ASSIGN                                                       !6, <true>
   33    60    > > JMP                                                          ->61
    7    61    >   PRE_INC                                                      !3
         62    >   IS_SMALLER                                                   !3, !4
         63      > JMPNZ                                                        ~44, ->13
   44    64    >   FRAMELESS_ICALL_1                implode             ~45     !1
         65      > RETURN                                                       ~45
   45    66*     > RETURN                                                       null

End of function munge

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
124.47 ms | 497 KiB | 15 Q