3v4l.org

run code in 300+ PHP versions simultaneously
<?php function toFraction($number){ $numerator = $number < 0 ? -1 : 1; $denominator = 0; for(; $numerator < 1000; $numerator++){ $temp = $numerator / $number; if(ceil($temp) - $temp == 0){ $denominator = $temp; break; } } return ($denominator > 0) ? $numerator . '/' . $denominator : false; } echo toFraction( -0.5) . "\n" . toFraction( 1.5);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TWvko
function name:  (null)
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   INIT_FCALL                                               'tofraction'
          1        SEND_VAL                                                 -0.5
          2        DO_FCALL                                      0  $0      
          3        CONCAT                                           ~1      $0, '%0A'
          4        INIT_FCALL                                               'tofraction'
          5        SEND_VAL                                                 1.5
          6        DO_FCALL                                      0  $2      
          7        CONCAT                                           ~3      ~1, $2
          8        ECHO                                                     ~3
          9      > RETURN                                                   1

Function tofraction:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 5
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 22, Position 2 = 9
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 28
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 19
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
Branch analysis from position: 19
2 jumps found. (Code = 44) Position 1 = 22, Position 2 = 9
Branch analysis from position: 22
Branch analysis from position: 9
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
filename:       /in/TWvko
function name:  toFraction
number of ops:  31
compiled vars:  !0 = $number, !1 = $numerator, !2 = $denominator, !3 = $temp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    3     1        IS_SMALLER                                               !0, 0
          2      > JMPZ                                                     ~4, ->5
          3    >   QM_ASSIGN                                        ~5      -1
          4      > JMP                                                      ->6
          5    >   QM_ASSIGN                                        ~5      1
          6    >   ASSIGN                                                   !1, ~5
    4     7        ASSIGN                                                   !2, 0
    5     8      > JMP                                                      ->20
    6     9    >   DIV                                              ~8      !1, !0
         10        ASSIGN                                                   !3, ~8
    7    11        INIT_FCALL                                               'ceil'
         12        SEND_VAR                                                 !3
         13        DO_ICALL                                         $10     
         14        SUB                                              ~11     $10, !3
         15        IS_EQUAL                                                 ~11, 0
         16      > JMPZ                                                     ~12, ->19
    8    17    >   ASSIGN                                                   !2, !3
    9    18      > JMP                                                      ->22
    5    19    >   PRE_INC                                                  !1
         20    >   IS_SMALLER                                               !1, 1000
         21      > JMPNZ                                                    ~15, ->9
   12    22    >   IS_SMALLER                                               0, !2
         23      > JMPZ                                                     ~16, ->28
         24    >   CONCAT                                           ~17     !1, '%2F'
         25        CONCAT                                           ~18     ~17, !2
         26        QM_ASSIGN                                        ~19     ~18
         27      > JMP                                                      ->29
         28    >   QM_ASSIGN                                        ~19     <false>
         29    > > RETURN                                                   ~19
   13    30*     > RETURN                                                   null

End of function tofraction

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.28 ms | 1394 KiB | 17 Q