3v4l.org

run code in 300+ PHP versions simultaneously
<?php function isPalindrome(string &$str): bool { if (strlen($str) <= 1) { return true; // reached the middle of the palindrome successfully } if ($str[0] !== $str[strlen($str) - 1]) { return false; // outermost characters are not identical, halt processing } $str = substr($str, 1, -1); return (__FUNCTION__)($str); // traverse deeper and bubble outcome to top level } function sanitizePalindrome(&$str) { return preg_replace('/[^a-z]+/', '', strtolower($str)); } $tests = [ 'radar', 'f', 'neveroddoreven', 'foo', 'palindrome', 'Red rum, sir, is murder' ]; foreach ($tests as $test) { $test = sanitizePalindrome($test); // this is optional printf("%20s : %s\n", $test, json_encode(isPalindrome($test))); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 19
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 19
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/AcjTr
function name:  (null)
number of ops:  21
compiled vars:  !0 = $tests, !1 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   ASSIGN                                                   !0, <array>
   28     1      > FE_RESET_R                                       $3      !0, ->19
          2    > > FE_FETCH_R                                               $3, !1, ->19
   29     3    >   INIT_FCALL                                               'sanitizepalindrome'
          4        SEND_REF                                                 !1
          5        DO_FCALL                                      0  $4      
          6        ASSIGN                                                   !1, $4
   30     7        INIT_FCALL                                               'printf'
          8        SEND_VAL                                                 '%2520s+%3A+%25s%0A'
          9        SEND_VAR                                                 !1
         10        INIT_FCALL                                               'json_encode'
         11        INIT_FCALL                                               'ispalindrome'
         12        SEND_REF                                                 !1
         13        DO_FCALL                                      0  $6      
         14        SEND_VAR                                                 $6
         15        DO_ICALL                                         $7      
         16        SEND_VAR                                                 $7
         17        DO_ICALL                                                 
   28    18      > JMP                                                      ->2
         19    >   FE_FREE                                                  $3
   31    20      > RETURN                                                   1

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

End of function ispalindrome

Function sanitizepalindrome:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AcjTr
function name:  sanitizePalindrome
number of ops:  11
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
   17     1        INIT_FCALL                                               'preg_replace'
          2        SEND_VAL                                                 '%2F%5B%5Ea-z%5D%2B%2F'
          3        SEND_VAL                                                 ''
          4        INIT_FCALL                                               'strtolower'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $1      
          7        SEND_VAR                                                 $1
          8        DO_ICALL                                         $2      
          9      > RETURN                                                   $2
   18    10*     > RETURN                                                   null

End of function sanitizepalindrome

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
140.28 ms | 1009 KiB | 20 Q