3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Gist { public static function result( $url ) { $url = strtolower( $url[0] ); // Adjust the URL if it contains a specific file within the Gist. $fragment = strpos( $url, '#' ); if ( false !== $fragment ) { if ( str_contains( $url, '.js#' ) ) { $url = str_replace( '.js#file-', '.js?file=', $url ); } else { $url = str_replace( '#file-', '.js?file=', $url ); } $last_hyphen = strrpos( $url, '-' ); if ( false !== $last_hyphen && $last_hyphen > $fragment ) { $url[ $last_hyphen ] = '.'; } } elseif ( ! str_ends_with( $url, '.js' ) ) { $url .= '.js'; } // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript return '<script src="' . $url . '"></script>'; } } $urls = [ 'no extension' => [ 'url' => 'https://gist.github.com/costdev/796167d5f34ec55caf281e8f1fb82c8a#file-a_file', 'expected' => 'https://gist.github.com/costdev/796167d5f34ec55caf281e8f1fb82c8a.js#file-a_file', ], '.gitignore' => [ 'url' => 'https://gist.github.com/costdev/796167d5f34ec55caf281e8f1fb82c8a#file-gitignore', 'expected' => 'https://gist.github.com/costdev/796167d5f34ec55caf281e8f1fb82c8a.js#file-gitignore', ], ]; $failures = []; foreach ( $urls as $dataset => $data ) { $url = $data['url']; $expected = $data['expected']; $actual = Gist::result( [ $url ] ); if ( $actual === '<script src="' . $expected . '"></script>' ) { echo '.'; } else { echo 'F'; $failures[] = "Failure: $dataset\nExpected: $expected\nActual: $actual\n\n"; } } echo "\n\n", implode( "\n", $failures );
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 31
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 31
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 20
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
filename:       /in/U9kTh
function name:  (null)
number of ops:  39
compiled vars:  !0 = $urls, !1 = $failures, !2 = $data, !3 = $dataset, !4 = $url, !5 = $expected, !6 = $actual
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   ASSIGN                                                   !0, <array>
   41     1        ASSIGN                                                   !1, <array>
   43     2      > FE_RESET_R                                       $9      !0, ->31
          3    > > FE_FETCH_R                                       ~10     $9, !2, ->31
          4    >   ASSIGN                                                   !3, ~10
   44     5        FETCH_DIM_R                                      ~12     !2, 'url'
          6        ASSIGN                                                   !4, ~12
   45     7        FETCH_DIM_R                                      ~14     !2, 'expected'
          8        ASSIGN                                                   !5, ~14
   46     9        INIT_STATIC_METHOD_CALL                                  'Gist', 'result'
         10        INIT_ARRAY                                       ~16     !4
         11        SEND_VAL                                                 ~16
         12        DO_FCALL                                      0  $17     
         13        ASSIGN                                                   !6, $17
   48    14        CONCAT                                           ~19     '%3Cscript+src%3D%22', !5
         15        CONCAT                                           ~20     ~19, '%22%3E%3C%2Fscript%3E'
         16        IS_IDENTICAL                                             !6, ~20
         17      > JMPZ                                                     ~21, ->20
   49    18    >   ECHO                                                     '.'
   48    19      > JMP                                                      ->30
   51    20    >   ECHO                                                     'F'
   52    21        ROPE_INIT                                     7  ~24     'Failure%3A++'
         22        ROPE_ADD                                      1  ~24     ~24, !3
         23        ROPE_ADD                                      2  ~24     ~24, '%0AExpected%3A+'
         24        ROPE_ADD                                      3  ~24     ~24, !5
         25        ROPE_ADD                                      4  ~24     ~24, '%0AActual%3A+++'
         26        ROPE_ADD                                      5  ~24     ~24, !6
         27        ROPE_END                                      6  ~23     ~24, '%0A%0A'
         28        ASSIGN_DIM                                               !1
         29        OP_DATA                                                  ~23
   43    30    > > JMP                                                      ->3
         31    >   FE_FREE                                                  $9
   56    32        ECHO                                                     '%0A%0A'
         33        INIT_FCALL                                               'implode'
         34        SEND_VAL                                                 '%0A'
         35        SEND_VAR                                                 !1
         36        DO_ICALL                                         $28     
         37        ECHO                                                     $28
         38      > RETURN                                                   1

Class Gist:
Function result:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 44
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 25
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
2 jumps found. (Code = 46) Position 1 = 38, Position 2 = 40
Branch analysis from position: 38
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 43
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 51
Branch analysis from position: 51
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 43
Branch analysis from position: 40
Branch analysis from position: 25
2 jumps found. (Code = 46) Position 1 = 38, Position 2 = 40
Branch analysis from position: 38
Branch analysis from position: 40
Branch analysis from position: 44
2 jumps found. (Code = 43) Position 1 = 50, Position 2 = 51
Branch analysis from position: 50
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 51
filename:       /in/U9kTh
function name:  result
number of ops:  55
compiled vars:  !0 = $url, !1 = $fragment, !2 = $last_hyphen
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    5     1        INIT_FCALL                                               'strtolower'
          2        FETCH_DIM_R                                      ~3      !0, 0
          3        SEND_VAL                                                 ~3
          4        DO_ICALL                                         $4      
          5        ASSIGN                                                   !0, $4
    8     6        INIT_FCALL                                               'strpos'
          7        SEND_VAR                                                 !0
          8        SEND_VAL                                                 '%23'
          9        DO_ICALL                                         $6      
         10        ASSIGN                                                   !1, $6
    9    11        TYPE_CHECK                                  1018          !1
         12      > JMPZ                                                     ~8, ->44
   10    13    >   INIT_FCALL                                               'str_contains'
         14        SEND_VAR                                                 !0
         15        SEND_VAL                                                 '.js%23'
         16        DO_ICALL                                         $9      
         17      > JMPZ                                                     $9, ->25
   11    18    >   INIT_FCALL                                               'str_replace'
         19        SEND_VAL                                                 '.js%23file-'
         20        SEND_VAL                                                 '.js%3Ffile%3D'
         21        SEND_VAR                                                 !0
         22        DO_ICALL                                         $10     
         23        ASSIGN                                                   !0, $10
   10    24      > JMP                                                      ->31
   13    25    >   INIT_FCALL                                               'str_replace'
         26        SEND_VAL                                                 '%23file-'
         27        SEND_VAL                                                 '.js%3Ffile%3D'
         28        SEND_VAR                                                 !0
         29        DO_ICALL                                         $12     
         30        ASSIGN                                                   !0, $12
   16    31    >   INIT_FCALL                                               'strrpos'
         32        SEND_VAR                                                 !0
         33        SEND_VAL                                                 '-'
         34        DO_ICALL                                         $14     
         35        ASSIGN                                                   !2, $14
   18    36        TYPE_CHECK                                  1018  ~16     !2
         37      > JMPZ_EX                                          ~16     ~16, ->40
         38    >   IS_SMALLER                                       ~17     !1, !2
         39        BOOL                                             ~16     ~17
         40    > > JMPZ                                                     ~16, ->43
   19    41    >   ASSIGN_DIM                                               !0, !2
         42        OP_DATA                                                  '.'
    9    43    > > JMP                                                      ->51
   21    44    >   INIT_FCALL                                               'str_ends_with'
         45        SEND_VAR                                                 !0
         46        SEND_VAL                                                 '.js'
         47        DO_ICALL                                         $19     
         48        BOOL_NOT                                         ~20     $19
         49      > JMPZ                                                     ~20, ->51
   22    50    >   ASSIGN_OP                                     8          !0, '.js'
   26    51    >   CONCAT                                           ~22     '%3Cscript+src%3D%22', !0
         52        CONCAT                                           ~23     ~22, '%22%3E%3C%2Fscript%3E'
         53      > RETURN                                                   ~23
   27    54*     > RETURN                                                   null

End of function result

End of class Gist.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.42 ms | 1026 KiB | 20 Q