3v4l.org

run code in 300+ PHP versions simultaneously
<?php function isPalindrome(string &$str): bool { return (bool) preg_match('/^(?=.)((.)(?1)\2|.?)$/', $str); } 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/FTuN3
function name:  (null)
number of ops:  21
compiled vars:  !0 = $tests, !1 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   ASSIGN                                                   !0, <array>
   22     1      > FE_RESET_R                                       $3      !0, ->19
          2    > > FE_FETCH_R                                               $3, !1, ->19
   23     3    >   INIT_FCALL                                               'sanitizepalindrome'
          4        SEND_REF                                                 !1
          5        DO_FCALL                                      0  $4      
          6        ASSIGN                                                   !1, $4
   24     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                                                 
   22    18      > JMP                                                      ->2
         19    >   FE_FREE                                                  $3
   25    20      > RETURN                                                   1

Function ispalindrome:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FTuN3
function name:  isPalindrome
number of ops:  10
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        INIT_FCALL                                               'preg_match'
          2        SEND_VAL                                                 '%2F%5E%28%3F%3D.%29%28%28.%29%28%3F1%29%5C2%7C.%3F%29%24%2F'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $1      
          5        BOOL                                             ~2      $1
          6        VERIFY_RETURN_TYPE                                       ~2
          7      > RETURN                                                   ~2
    6     8*       VERIFY_RETURN_TYPE                                       
          9*     > 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/FTuN3
function name:  sanitizePalindrome
number of ops:  11
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
   10     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
   11    10*     > RETURN                                                   null

End of function sanitizepalindrome

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.68 ms | 1009 KiB | 20 Q