3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); var_dump(PrimePalindromeFinder::find(1000, 1)); var_dump(PrimePalindromeFinder::find(10, 1)); var_dump(PrimePalindromeFinder::find(500, 400)); var_dump(PrimePalindromeFinder::findStrict(1000, 1)); var_dump(PrimePalindromeFinder::findStrict(10, 1)); try { var_dump(PrimePalindromeFinder::findStrict(500, 400)); } catch(\Exception $e) { var_dump($e->getMessage()); } class PrimePalindromeFinder { public static function find(int $start, int $end) { for($i = $start; $i >= $end; $i--) { if(self::isPalindrome($i) && self::isPrime($i)) { return $i; } } return false; } public static function findStrict(int $start, int $end):int { for($i = $start; $i >= $end; $i--) { if(self::isPalindrome($i) && self::isPrime($i)) { return $i; } } throw new \Exception("No Prime Palindrome found between {$start} and {$end}"); } private static function isPalindrome(int $number):bool { $number = strval($number); for($i = 1; $i <= floor(strlen($number) / 2); $i++) { $from_start = substr($number, $i - 1, 1); $from_end = substr($number, $i * -1, 1); if($from_start !== $from_end) { return false; } } return true; } private static function isPrime(int $number):bool { if($number == 1) { return false; } if($number == 2) { return true; } if($number % 2 == 0) { return false; } for($i = 3; $i <= ceil(sqrt($number)); $i = $i + 2) { if($number % $i == 0) return false; } return true; } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
1 jumps found. (Code = 62) Position 1 = -2
Found catch point at position: 43
Branch analysis from position: 43
2 jumps found. (Code = 107) Position 1 = 44, Position 2 = -2
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1CVHB
function name:  (null)
number of ops:  50
compiled vars:  !0 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_STATIC_METHOD_CALL                                  'PrimePalindromeFinder', 'find'
          2        SEND_VAL_EX                                              1000
          3        SEND_VAL_EX                                              1
          4        DO_FCALL                                      0  $1      
          5        SEND_VAR                                                 $1
          6        DO_ICALL                                                 
    5     7        INIT_FCALL                                               'var_dump'
          8        INIT_STATIC_METHOD_CALL                                  'PrimePalindromeFinder', 'find'
          9        SEND_VAL_EX                                              10
         10        SEND_VAL_EX                                              1
         11        DO_FCALL                                      0  $3      
         12        SEND_VAR                                                 $3
         13        DO_ICALL                                                 
    6    14        INIT_FCALL                                               'var_dump'
         15        INIT_STATIC_METHOD_CALL                                  'PrimePalindromeFinder', 'find'
         16        SEND_VAL_EX                                              500
         17        SEND_VAL_EX                                              400
         18        DO_FCALL                                      0  $5      
         19        SEND_VAR                                                 $5
         20        DO_ICALL                                                 
    8    21        INIT_FCALL                                               'var_dump'
         22        INIT_STATIC_METHOD_CALL                                  'PrimePalindromeFinder', 'findStrict'
         23        SEND_VAL_EX                                              1000
         24        SEND_VAL_EX                                              1
         25        DO_FCALL                                      0  $7      
         26        SEND_VAR                                                 $7
         27        DO_ICALL                                                 
    9    28        INIT_FCALL                                               'var_dump'
         29        INIT_STATIC_METHOD_CALL                                  'PrimePalindromeFinder', 'findStrict'
         30        SEND_VAL_EX                                              10
         31        SEND_VAL_EX                                              1
         32        DO_FCALL                                      0  $9      
         33        SEND_VAR                                                 $9
         34        DO_ICALL                                                 
   11    35        INIT_FCALL                                               'var_dump'
         36        INIT_STATIC_METHOD_CALL                                  'PrimePalindromeFinder', 'findStrict'
         37        SEND_VAL_EX                                              500
         38        SEND_VAL_EX                                              400
         39        DO_FCALL                                      0  $11     
         40        SEND_VAR                                                 $11
         41        DO_ICALL                                                 
         42      > JMP                                                      ->49
   12    43  E > > CATCH                                       last         'Exception'
   13    44    >   INIT_FCALL                                               'var_dump'
         45        INIT_METHOD_CALL                                         !0, 'getMessage'
         46        DO_FCALL                                      0  $13     
         47        SEND_VAR                                                 $13
         48        DO_ICALL                                                 
   64    49    > > RETURN                                                   1

Class PrimePalindromeFinder:
Function find:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 4
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 46) Position 1 = 8, Position 2 = 12
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 14
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 4
Branch analysis from position: 17
Branch analysis from position: 4
Branch analysis from position: 12
filename:       /in/1CVHB
function name:  find
number of ops:  19
compiled vars:  !0 = $start, !1 = $end, !2 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   18     2        ASSIGN                                                   !2, !0
          3      > JMP                                                      ->15
   19     4    >   INIT_STATIC_METHOD_CALL                                  'isPalindrome'
          5        SEND_VAR_EX                                              !2
          6        DO_FCALL                                      0  $4      
          7      > JMPZ_EX                                          ~5      $4, ->12
          8    >   INIT_STATIC_METHOD_CALL                                  'isPrime'
          9        SEND_VAR_EX                                              !2
         10        DO_FCALL                                      0  $6      
         11        BOOL                                             ~5      $6
         12    > > JMPZ                                                     ~5, ->14
   20    13    > > RETURN                                                   !2
   18    14    >   PRE_DEC                                                  !2
         15    >   IS_SMALLER_OR_EQUAL                                      !1, !2
         16      > JMPNZ                                                    ~8, ->4
   23    17    > > RETURN                                                   <false>
   24    18*     > RETURN                                                   null

End of function find

Function findstrict:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 4
Branch analysis from position: 18
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 46) Position 1 = 8, Position 2 = 12
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 15
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 4
Branch analysis from position: 18
Branch analysis from position: 4
Branch analysis from position: 12
filename:       /in/1CVHB
function name:  findStrict
number of ops:  28
compiled vars:  !0 = $start, !1 = $end, !2 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   27     2        ASSIGN                                                   !2, !0
          3      > JMP                                                      ->16
   28     4    >   INIT_STATIC_METHOD_CALL                                  'isPalindrome'
          5        SEND_VAR_EX                                              !2
          6        DO_FCALL                                      0  $4      
          7      > JMPZ_EX                                          ~5      $4, ->12
          8    >   INIT_STATIC_METHOD_CALL                                  'isPrime'
          9        SEND_VAR_EX                                              !2
         10        DO_FCALL                                      0  $6      
         11        BOOL                                             ~5      $6
         12    > > JMPZ                                                     ~5, ->15
   29    13    >   VERIFY_RETURN_TYPE                                       !2
         14      > RETURN                                                   !2
   27    15    >   PRE_DEC                                                  !2
         16    >   IS_SMALLER_OR_EQUAL                                      !1, !2
         17      > JMPNZ                                                    ~8, ->4
   32    18    >   NEW                                              $9      'Exception'
         19        ROPE_INIT                                     4  ~11     'No+Prime+Palindrome+found+between+'
         20        ROPE_ADD                                      1  ~11     ~11, !0
         21        ROPE_ADD                                      2  ~11     ~11, '+and+'
         22        ROPE_END                                      3  ~10     ~11, !1
         23        SEND_VAL_EX                                              ~10
         24        DO_FCALL                                      0          
         25      > THROW                                         0          $9
   33    26*       VERIFY_RETURN_TYPE                                       
         27*     > RETURN                                                   null

End of function findstrict

Function ispalindrome:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 30, Position 2 = 5
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 22
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 30, Position 2 = 5
Branch analysis from position: 30
Branch analysis from position: 5
filename:       /in/1CVHB
function name:  isPalindrome
number of ops:  33
compiled vars:  !0 = $number, !1 = $i, !2 = $from_start, !3 = $from_end
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
   36     1        CAST                                          6  ~4      !0
          2        ASSIGN                                                   !0, ~4
   37     3        ASSIGN                                                   !1, 1
          4      > JMP                                                      ->23
   38     5    >   INIT_FCALL                                               'substr'
          6        SEND_VAR                                                 !0
          7        SUB                                              ~7      !1, 1
          8        SEND_VAL                                                 ~7
          9        SEND_VAL                                                 1
         10        DO_ICALL                                         $8      
         11        ASSIGN                                                   !2, $8
   39    12        INIT_FCALL                                               'substr'
         13        SEND_VAR                                                 !0
         14        MUL                                              ~10     !1, -1
         15        SEND_VAL                                                 ~10
         16        SEND_VAL                                                 1
         17        DO_ICALL                                         $11     
         18        ASSIGN                                                   !3, $11
   40    19        IS_NOT_IDENTICAL                                         !2, !3
         20      > JMPZ                                                     ~13, ->22
   41    21    > > RETURN                                                   <false>
   37    22    >   PRE_INC                                                  !1
         23    >   INIT_FCALL                                               'floor'
         24        STRLEN                                           ~15     !0
         25        DIV                                              ~16     ~15, 2
         26        SEND_VAL                                                 ~16
         27        DO_ICALL                                         $17     
         28        IS_SMALLER_OR_EQUAL                                      !1, $17
         29      > JMPNZ                                                    ~18, ->5
   44    30    > > RETURN                                                   <true>
   45    31*       VERIFY_RETURN_TYPE                                       
         32*     > RETURN                                                   null

End of function ispalindrome

Function isprime:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 4
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 7
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 11
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 13
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 17
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 13
Branch analysis from position: 27
Branch analysis from position: 13
filename:       /in/1CVHB
function name:  isPrime
number of ops:  30
compiled vars:  !0 = $number, !1 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   RECV                                             !0      
   48     1        IS_EQUAL                                                 !0, 1
          2      > JMPZ                                                     ~2, ->4
   49     3    > > RETURN                                                   <false>
   51     4    >   IS_EQUAL                                                 !0, 2
          5      > JMPZ                                                     ~3, ->7
   52     6    > > RETURN                                                   <true>
   54     7    >   MOD                                              ~4      !0, 2
          8        IS_EQUAL                                                 ~4, 0
          9      > JMPZ                                                     ~5, ->11
   55    10    > > RETURN                                                   <false>
   57    11    >   ASSIGN                                                   !1, 3
         12      > JMP                                                      ->19
   58    13    >   MOD                                              ~7      !0, !1
         14        IS_EQUAL                                                 ~7, 0
         15      > JMPZ                                                     ~8, ->17
   59    16    > > RETURN                                                   <false>
   57    17    >   ADD                                              ~9      !1, 2
         18        ASSIGN                                                   !1, ~9
         19    >   INIT_FCALL                                               'ceil'
         20        INIT_FCALL                                               'sqrt'
         21        SEND_VAR                                                 !0
         22        DO_ICALL                                         $11     
         23        SEND_VAR                                                 $11
         24        DO_ICALL                                         $12     
         25        IS_SMALLER_OR_EQUAL                                      !1, $12
         26      > JMPNZ                                                    ~13, ->13
   62    27    > > RETURN                                                   <true>
   63    28*       VERIFY_RETURN_TYPE                                       
         29*     > RETURN                                                   null

End of function isprime

End of class PrimePalindromeFinder.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
191.34 ms | 1412 KiB | 23 Q