3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace JoshDiFabio; interface RomanNumeralGeneratorInterface { /** * @param int $number * @return string * @throws \InvalidArgumentException Argument not an integer or out of range * @author Josh Di Fabio <joshdifabio@hotmail.com> */ public function generate($number); } class RomanNumeral { const ONE = 'I'; const FIVE = 'V'; const TEN = 'X'; const FIFTY = 'L'; const ONE_HUNDRED = 'C'; const FIVE_HUNDRED = 'D'; const ONE_THOUSAND = 'M'; } class RomanNumeralGenerator implements RomanNumeralGeneratorInterface { /** * @var array * @author Josh Di Fabio <joshdifabio@hotmail.com> */ private $_integerNumeralMap = array( 1000 => RomanNumeral::ONE_THOUSAND, 500 => RomanNumeral::FIVE_HUNDRED, 100 => RomanNumeral::ONE_HUNDRED, 50 => RomanNumeral::FIFTY, 10 => RomanNumeral::TEN, 5 => RomanNumeral::FIVE, 1 => RomanNumeral::ONE, ); /** * @param int $number * @return string * @throws \InvalidArgumentException Argument not an integer or out of range * @author Josh Di Fabio <joshdifabio@hotmail.com> */ public function generate($number) { if (!is_integer($number)) { throw new \InvalidArgumentException('Provided argument is not an integer.'); } if (1 > $number || 3999 < $number) { throw new \InvalidArgumentException( 'The provided number is not within the allowed range of 1 to 3999.'); } $numerals = array(); while (0 < $number) { foreach ($this->_integerNumeralMap as $_integer => $_numeral) { if ($number >= $_integer) { $numerals[] = $_numeral; $number -= $_integer; break; } } } return implode('', $numerals); } } $generator = new RomanNumeralGenerator; echo $generator->generate(312);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0MAqU
function name:  (null)
number of ops:  9
compiled vars:  !0 = $generator
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   DECLARE_CLASS                                            'joshdifabio%5Cromannumeralgenerator'
   74     1        NEW                                              $1      'JoshDiFabio%5CRomanNumeralGenerator'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $1
   75     4        INIT_METHOD_CALL                                         !0, 'generate'
          5        SEND_VAL_EX                                              312
          6        DO_FCALL                                      0  $4      
          7        ECHO                                                     $4
          8      > RETURN                                                   1

Class JoshDiFabio\RomanNumeralGeneratorInterface:
Function generate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0MAqU
function name:  generate
number of ops:  2
compiled vars:  !0 = $number
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function generate

End of class JoshDiFabio\RomanNumeralGeneratorInterface.

Class JoshDiFabio\RomanNumeral: [no user functions]
Class JoshDiFabio\RomanNumeralGenerator:
Function generate:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 10
Branch analysis from position: 6
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 10
2 jumps found. (Code = 47) Position 1 = 12, Position 2 = 14
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 19
Branch analysis from position: 15
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
2 jumps found. (Code = 44) Position 1 = 35, Position 2 = 21
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
2 jumps found. (Code = 77) Position 1 = 23, Position 2 = 32
Branch analysis from position: 23
2 jumps found. (Code = 78) Position 1 = 24, Position 2 = 32
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 31
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
2 jumps found. (Code = 44) Position 1 = 35, Position 2 = 21
Branch analysis from position: 35
Branch analysis from position: 21
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Branch analysis from position: 32
Branch analysis from position: 32
Branch analysis from position: 14
filename:       /in/0MAqU
function name:  generate
number of ops:  41
compiled vars:  !0 = $number, !1 = $numerals, !2 = $_numeral, !3 = $_integer
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   48     0  E >   RECV                                             !0      
   50     1        INIT_NS_FCALL_BY_NAME                                    'JoshDiFabio%5Cis_integer'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $4      
          4        BOOL_NOT                                         ~5      $4
          5      > JMPZ                                                     ~5, ->10
   51     6    >   NEW                                              $6      'InvalidArgumentException'
          7        SEND_VAL_EX                                              'Provided+argument+is+not+an+integer.'
          8        DO_FCALL                                      0          
          9      > THROW                                         0          $6
   53    10    >   IS_SMALLER                                       ~8      !0, 1
         11      > JMPNZ_EX                                         ~8      ~8, ->14
         12    >   IS_SMALLER                                       ~9      3999, !0
         13        BOOL                                             ~8      ~9
         14    > > JMPZ                                                     ~8, ->19
   54    15    >   NEW                                              $10     'InvalidArgumentException'
   55    16        SEND_VAL_EX                                              'The+provided+number+is+not+within+the+allowed+range+of+1+to+3999.'
         17        DO_FCALL                                      0          
         18      > THROW                                         0          $10
   58    19    >   ASSIGN                                                   !1, <array>
   60    20      > JMP                                                      ->33
   61    21    >   FETCH_OBJ_R                                      ~13     '_integerNumeralMap'
         22      > FE_RESET_R                                       $14     ~13, ->32
         23    > > FE_FETCH_R                                       ~15     $14, !2, ->32
         24    >   ASSIGN                                                   !3, ~15
   62    25        IS_SMALLER_OR_EQUAL                                      !3, !0
         26      > JMPZ                                                     ~17, ->31
   63    27    >   ASSIGN_DIM                                               !1
         28        OP_DATA                                                  !2
   64    29        ASSIGN_OP                                     2          !0, !3
   65    30      > JMP                                                      ->32
   61    31    > > JMP                                                      ->23
         32    >   FE_FREE                                                  $14
   60    33    >   IS_SMALLER                                               0, !0
         34      > JMPNZ                                                    ~20, ->21
   70    35    >   INIT_NS_FCALL_BY_NAME                                    'JoshDiFabio%5Cimplode'
         36        SEND_VAL_EX                                              ''
         37        SEND_VAR_EX                                              !1
         38        DO_FCALL                                      0  $21     
         39      > RETURN                                                   $21
   71    40*     > RETURN                                                   null

End of function generate

End of class JoshDiFabio\RomanNumeralGenerator.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.36 ms | 1403 KiB | 16 Q