3v4l.org

run code in 300+ PHP versions simultaneously
<?php function is_palindrome($str) { $len = strlen($str); if ($len < 2) { // strings of 0 or 1 characters are palindromes return true; } elseif ($str[0] != $str[$len-1]) { // first character doesn't match last character, so not a palindrome return false; } else { // first character is equal to last character, // so see if the rest of the string is a palindrome return is_palindrome(substr($str, 1, $len - 2)); } } foreach (['rotor', 'a', 'deed', 'hello', 'xyyz'] as $str) { echo "\"$str\" is" . (is_palindrome($str) ? "" : " not") . " a palindrome\n"; } function is_palindrome_broken($str) { $len = strlen($str); if ($len < 2) { // strings of 0 or 1 characters are palindromes return true; } elseif ($str[0] != $str[$len-1]) { // first character doesn't match last character, so not a palindrome return false; } else { // first character is equal to last character, // so see if the rest of the string is a palindrome is_palindrome_broken(substr($str, 1, $len - 2)); } } foreach (['rotor', 'a', 'deed', 'hello', 'xyyz'] as $str) { echo "\"$str\" is" . (is_palindrome_broken($str) ? "" : " not") . " a palindrome\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 1, Position 2 = 16
Branch analysis from position: 1
2 jumps found. (Code = 78) Position 1 = 2, Position 2 = 16
Branch analysis from position: 2
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 11
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 1
Branch analysis from position: 1
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 1
Branch analysis from position: 1
Branch analysis from position: 16
2 jumps found. (Code = 77) Position 1 = 18, Position 2 = 33
Branch analysis from position: 18
2 jumps found. (Code = 78) Position 1 = 19, Position 2 = 33
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 28
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
Branch analysis from position: 16
filename:       /in/NlsF9
function name:  (null)
number of ops:  35
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E > > FE_RESET_R                                       $1      <array>, ->16
          1    > > FE_FETCH_R                                               $1, !0, ->16
   21     2    >   ROPE_INIT                                     3  ~3      '%22'
          3        ROPE_ADD                                      1  ~3      ~3, !0
          4        ROPE_END                                      2  ~2      ~3, '%22+is'
          5        INIT_FCALL                                               'is_palindrome'
          6        SEND_VAR                                                 !0
          7        DO_FCALL                                      0  $5      
          8      > JMPZ                                                     $5, ->11
          9    >   QM_ASSIGN                                        ~6      ''
         10      > JMP                                                      ->12
         11    >   QM_ASSIGN                                        ~6      '+not'
         12    >   CONCAT                                           ~7      ~2, ~6
         13        CONCAT                                           ~8      ~7, '+a+palindrome%0A'
         14        ECHO                                                     ~8
   20    15      > JMP                                                      ->1
         16    >   FE_FREE                                                  $1
   41    17      > FE_RESET_R                                       $9      <array>, ->33
         18    > > FE_FETCH_R                                               $9, !0, ->33
   42    19    >   ROPE_INIT                                     3  ~11     '%22'
         20        ROPE_ADD                                      1  ~11     ~11, !0
         21        ROPE_END                                      2  ~10     ~11, '%22+is'
         22        INIT_FCALL                                               'is_palindrome_broken'
         23        SEND_VAR                                                 !0
         24        DO_FCALL                                      0  $13     
         25      > JMPZ                                                     $13, ->28
         26    >   QM_ASSIGN                                        ~14     ''
         27      > JMP                                                      ->29
         28    >   QM_ASSIGN                                        ~14     '+not'
         29    >   CONCAT                                           ~15     ~10, ~14
         30        CONCAT                                           ~16     ~15, '+a+palindrome%0A'
         31        ECHO                                                     ~16
   41    32      > JMP                                                      ->18
         33    >   FE_FREE                                                  $9
   43    34      > RETURN                                                   1

Function is_palindrome:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 7
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 14
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NlsF9
function name:  is_palindrome
number of ops:  25
compiled vars:  !0 = $str, !1 = $len
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        STRLEN                                           ~2      !0
          2        ASSIGN                                                   !1, ~2
    5     3        IS_SMALLER                                               !1, 2
          4      > JMPZ                                                     ~4, ->7
    7     5    > > RETURN                                                   <true>
          6*       JMP                                                      ->24
    9     7    >   FETCH_DIM_R                                      ~5      !0, 0
          8        SUB                                              ~6      !1, 1
          9        FETCH_DIM_R                                      ~7      !0, ~6
         10        IS_NOT_EQUAL                                             ~5, ~7
         11      > JMPZ                                                     ~8, ->14
   11    12    > > RETURN                                                   <false>
         13*       JMP                                                      ->24
   16    14    >   INIT_FCALL_BY_NAME                                       'is_palindrome'
         15        INIT_FCALL                                               'substr'
         16        SEND_VAR                                                 !0
         17        SEND_VAL                                                 1
         18        SUB                                              ~9      !1, 2
         19        SEND_VAL                                                 ~9
         20        DO_ICALL                                         $10     
         21        SEND_VAR_NO_REF_EX                                       $10
         22        DO_FCALL                                      0  $11     
         23      > RETURN                                                   $11
   18    24*     > RETURN                                                   null

End of function is_palindrome

Function is_palindrome_broken:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 7
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 14
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NlsF9
function name:  is_palindrome_broken
number of ops:  24
compiled vars:  !0 = $str, !1 = $len
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   25     1        STRLEN                                           ~2      !0
          2        ASSIGN                                                   !1, ~2
   26     3        IS_SMALLER                                               !1, 2
          4      > JMPZ                                                     ~4, ->7
   28     5    > > RETURN                                                   <true>
          6*       JMP                                                      ->23
   30     7    >   FETCH_DIM_R                                      ~5      !0, 0
          8        SUB                                              ~6      !1, 1
          9        FETCH_DIM_R                                      ~7      !0, ~6
         10        IS_NOT_EQUAL                                             ~5, ~7
         11      > JMPZ                                                     ~8, ->14
   32    12    > > RETURN                                                   <false>
         13*       JMP                                                      ->23
   37    14    >   INIT_FCALL_BY_NAME                                       'is_palindrome_broken'
         15        INIT_FCALL                                               'substr'
         16        SEND_VAR                                                 !0
         17        SEND_VAL                                                 1
         18        SUB                                              ~9      !1, 2
         19        SEND_VAL                                                 ~9
         20        DO_ICALL                                         $10     
         21        SEND_VAR_NO_REF_EX                                       $10
         22        DO_FCALL                                      0          
   39    23      > RETURN                                                   null

End of function is_palindrome_broken

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.32 ms | 1407 KiB | 17 Q