3v4l.org

run code in 300+ PHP versions simultaneously
<?php $closestRadix = function(int $num) : int { $index = floor(log($num, 10)); $nextMag = 10**($index+1); return $nextMag - $num > $nextMag / 2 ? $index: $index + 1; }; $numDigits = function(int $num) : int { return floor(log($num, 10)) + 1; }; $isEven = function(int $num) : bool { return $num % 2 == 0; }; $isEvenNumberOfDigits = function(int $num) : bool { return $isEven($numDigits($num)); }; $mirror = function(int $num, bool $parityCase = false) : int { echo $num . "\n"; return (int)($parityCase ? substr((string)$num, 0, -1) : (string)$num . strrev((string)$num)); }; $halves = function(int $num) use ($isEvenNumberOfDigits, $numDigits) : array { $digitsPerHalf = $isEvenNumberOfDigits ? $numDigits($num)/2 : ceil($numDigits($num)/2); return [ substr((string)$num, 0, $digitsPerHalf), substr((string)$num, $digitsPerHalf, $digitsPerHalf) ]; }; $nextPalindrome = function(int $num) use ($halves, $mirror) : int { print_r($halves($num)); $smallestHalf = min($halves($num)); echo $smallestHalf . "\n"; return $halves($num)[0] == $smallestHalf ? $mirror($halves($num)[0])+1 : $mirror($halves($num)[1]); }; echo $nextPalindrome(110); ?> === 110 120 -> 121 999 1312 1314 -> 1331 121 131 191 202 1221 3113 9999
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jLTBq
function name:  (null)
number of ops:  24
compiled vars:  !0 = $closestRadix, !1 = $numDigits, !2 = $isEven, !3 = $isEvenNumberOfDigits, !4 = $mirror, !5 = $halves, !6 = $nextPalindrome
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FjLTBq%3A3%240'
          1        ASSIGN                                                   !0, ~7
   10     2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FjLTBq%3A10%241'
          3        ASSIGN                                                   !1, ~9
   14     4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FjLTBq%3A14%242'
          5        ASSIGN                                                   !2, ~11
   18     6        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FjLTBq%3A18%243'
          7        ASSIGN                                                   !3, ~13
   22     8        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FjLTBq%3A22%244'
          9        ASSIGN                                                   !4, ~15
   27    10        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FjLTBq%3A27%245'
         11        BIND_LEXICAL                                             ~17, !3
         12        BIND_LEXICAL                                             ~17, !1
         13        ASSIGN                                                   !5, ~17
   35    14        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FjLTBq%3A35%246'
         15        BIND_LEXICAL                                             ~19, !5
         16        BIND_LEXICAL                                             ~19, !4
         17        ASSIGN                                                   !6, ~19
   42    18        INIT_DYNAMIC_CALL                                        !6
         19        SEND_VAL_EX                                              110
         20        DO_FCALL                                      0  $21     
         21        ECHO                                                     $21
   45    22        ECHO                                                     '%0A%0A%3D%3D%3D%0A110%0A120++-%3E+121%0A%0A%0A999%0A%0A1312%0A1314+-%3E+1331%0A%0A%0A%0A121%0A131%0A191%0A202%0A1221%0A3113%0A%0A9999'
   66    23      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FjLTBq%3A3%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 18
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jLTBq
function name:  {closure}
number of ops:  24
compiled vars:  !0 = $num, !1 = $index, !2 = $nextMag
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        INIT_FCALL                                               'floor'
          2        INIT_FCALL                                               'log'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 10
          5        DO_ICALL                                         $3      
          6        SEND_VAR                                                 $3
          7        DO_ICALL                                         $4      
          8        ASSIGN                                                   !1, $4
    5     9        ADD                                              ~6      !1, 1
         10        POW                                              ~7      10, ~6
         11        ASSIGN                                                   !2, ~7
    7    12        SUB                                              ~9      !2, !0
         13        DIV                                              ~10     !2, 2
         14        IS_SMALLER                                               ~10, ~9
         15      > JMPZ                                                     ~11, ->18
         16    >   QM_ASSIGN                                        ~12     !1
         17      > JMP                                                      ->20
         18    >   ADD                                              ~13     !1, 1
         19        QM_ASSIGN                                        ~12     ~13
         20    >   VERIFY_RETURN_TYPE                                       ~12
         21      > RETURN                                                   ~12
    8    22*       VERIFY_RETURN_TYPE                                       
         23*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FjLTBq%3A3%240

Function %00%7Bclosure%7D%2Fin%2FjLTBq%3A10%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jLTBq
function name:  {closure}
number of ops:  13
compiled vars:  !0 = $num
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
   11     1        INIT_FCALL                                               'floor'
          2        INIT_FCALL                                               'log'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 10
          5        DO_ICALL                                         $1      
          6        SEND_VAR                                                 $1
          7        DO_ICALL                                         $2      
          8        ADD                                              ~3      $2, 1
          9        VERIFY_RETURN_TYPE                                       ~3
         10      > RETURN                                                   ~3
   12    11*       VERIFY_RETURN_TYPE                                       
         12*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FjLTBq%3A10%241

Function %00%7Bclosure%7D%2Fin%2FjLTBq%3A14%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jLTBq
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $num
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   15     1        MOD                                              ~1      !0, 2
          2        IS_EQUAL                                         ~2      ~1, 0
          3        VERIFY_RETURN_TYPE                                       ~2
          4      > RETURN                                                   ~2
   16     5*       VERIFY_RETURN_TYPE                                       
          6*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FjLTBq%3A14%242

Function %00%7Bclosure%7D%2Fin%2FjLTBq%3A18%243:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jLTBq
function name:  {closure}
number of ops:  11
compiled vars:  !0 = $num, !1 = $isEven, !2 = $numDigits
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
   19     1        INIT_DYNAMIC_CALL                                        !1
          2        INIT_DYNAMIC_CALL                                        !2
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $3      
          5        SEND_VAR_NO_REF_EX                                       $3
          6        DO_FCALL                                      0  $4      
          7        VERIFY_RETURN_TYPE                                       $4
          8      > RETURN                                                   $4
   20     9*       VERIFY_RETURN_TYPE                                       
         10*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FjLTBq%3A18%243

Function %00%7Bclosure%7D%2Fin%2FjLTBq%3A22%244:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 13
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jLTBq
function name:  {closure}
number of ops:  25
compiled vars:  !0 = $num, !1 = $parityCase
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <false>
   23     2        CONCAT                                           ~2      !0, '%0A'
          3        ECHO                                                     ~2
   24     4      > JMPZ                                                     !1, ->13
          5    >   INIT_FCALL                                               'substr'
          6        CAST                                          6  ~3      !0
          7        SEND_VAL                                                 ~3
          8        SEND_VAL                                                 0
          9        SEND_VAL                                                 -1
         10        DO_ICALL                                         $4      
         11        QM_ASSIGN                                        ~5      $4
         12      > JMP                                                      ->20
         13    >   CAST                                          6  ~6      !0
         14        INIT_FCALL                                               'strrev'
         15        CAST                                          6  ~7      !0
         16        SEND_VAL                                                 ~7
         17        DO_ICALL                                         $8      
         18        CONCAT                                           ~9      ~6, $8
         19        QM_ASSIGN                                        ~5      ~9
         20    >   CAST                                          4  ~10     ~5
         21        VERIFY_RETURN_TYPE                                       ~10
         22      > RETURN                                                   ~10
   25    23*       VERIFY_RETURN_TYPE                                       
         24*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FjLTBq%3A22%244

Function %00%7Bclosure%7D%2Fin%2FjLTBq%3A27%245:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jLTBq
function name:  {closure}
number of ops:  37
compiled vars:  !0 = $num, !1 = $isEvenNumberOfDigits, !2 = $numDigits, !3 = $digitsPerHalf
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
   28     3      > JMPZ                                                     !1, ->10
          4    >   INIT_DYNAMIC_CALL                                        !2
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0  $4      
          7        DIV                                              ~5      $4, 2
          8        QM_ASSIGN                                        ~6      ~5
          9      > JMP                                                      ->18
         10    >   INIT_FCALL                                               'ceil'
         11        INIT_DYNAMIC_CALL                                        !2
         12        SEND_VAR_EX                                              !0
         13        DO_FCALL                                      0  $7      
         14        DIV                                              ~8      $7, 2
         15        SEND_VAL                                                 ~8
         16        DO_ICALL                                         $9      
         17        QM_ASSIGN                                        ~6      $9
         18    >   ASSIGN                                                   !3, ~6
   30    19        INIT_FCALL                                               'substr'
         20        CAST                                          6  ~11     !0
         21        SEND_VAL                                                 ~11
         22        SEND_VAL                                                 0
         23        SEND_VAR                                                 !3
         24        DO_ICALL                                         $12     
         25        INIT_ARRAY                                       ~13     $12
   31    26        INIT_FCALL                                               'substr'
         27        CAST                                          6  ~14     !0
         28        SEND_VAL                                                 ~14
         29        SEND_VAR                                                 !3
         30        SEND_VAR                                                 !3
         31        DO_ICALL                                         $15     
         32        ADD_ARRAY_ELEMENT                                ~13     $15
         33        VERIFY_RETURN_TYPE                                       ~13
         34      > RETURN                                                   ~13
   33    35*       VERIFY_RETURN_TYPE                                       
         36*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FjLTBq%3A27%245

Function %00%7Bclosure%7D%2Fin%2FjLTBq%3A35%246:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 36
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jLTBq
function name:  {closure}
number of ops:  50
compiled vars:  !0 = $num, !1 = $halves, !2 = $mirror, !3 = $smallestHalf
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
   36     3        INIT_FCALL                                               'print_r'
          4        INIT_DYNAMIC_CALL                                        !1
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0  $4      
          7        SEND_VAR                                                 $4
          8        DO_ICALL                                                 
   37     9        INIT_FCALL                                               'min'
         10        INIT_DYNAMIC_CALL                                        !1
         11        SEND_VAR_EX                                              !0
         12        DO_FCALL                                      0  $6      
         13        SEND_VAR                                                 $6
         14        DO_ICALL                                         $7      
         15        ASSIGN                                                   !3, $7
   38    16        CONCAT                                           ~9      !3, '%0A'
         17        ECHO                                                     ~9
   39    18        INIT_DYNAMIC_CALL                                        !1
         19        SEND_VAR_EX                                              !0
         20        DO_FCALL                                      0  $10     
         21        FETCH_DIM_R                                      ~11     $10, 0
         22        IS_EQUAL                                                 !3, ~11
         23      > JMPZ                                                     ~12, ->36
         24    >   INIT_DYNAMIC_CALL                                        !2
         25        CHECK_FUNC_ARG                                           
         26        INIT_DYNAMIC_CALL                                        !1
         27        SEND_VAR_EX                                              !0
         28        DO_FCALL                                      0  $13     
         29        SEPARATE                                         $13     $13
         30        FETCH_DIM_FUNC_ARG                               $14     $13, 0
         31        SEND_FUNC_ARG                                            $14
         32        DO_FCALL                                      0  $15     
         33        ADD                                              ~16     $15, 1
         34        QM_ASSIGN                                        ~17     ~16
         35      > JMP                                                      ->46
         36    >   INIT_DYNAMIC_CALL                                        !2
         37        CHECK_FUNC_ARG                                           
         38        INIT_DYNAMIC_CALL                                        !1
         39        SEND_VAR_EX                                              !0
         40        DO_FCALL                                      0  $18     
         41        SEPARATE                                         $18     $18
         42        FETCH_DIM_FUNC_ARG                               $19     $18, 1
         43        SEND_FUNC_ARG                                            $19
         44        DO_FCALL                                      0  $20     
         45        QM_ASSIGN                                        ~17     $20
         46    >   VERIFY_RETURN_TYPE                                       ~17
         47      > RETURN                                                   ~17
   40    48*       VERIFY_RETURN_TYPE                                       
         49*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FjLTBq%3A35%246

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
182.27 ms | 1408 KiB | 27 Q