3v4l.org

run code in 300+ PHP versions simultaneously
<?php class GreatestCommonDivisor { /** * Get the divisor of a given number. * * @param int $num * The number. * * @return int[] * The divisors of the number. */ private function factors(int $num): array { return array_filter( range(1, $num), function (int $i) use ($num) { return 0 === $num % $i; } ); } /** * Get the greatest common divisor. * * @param int ...$x * The numbers. * * @return int * The greatest common divisor. */ public function gcd(...$x): int { $x = array_map([$this, 'factors'], $x); $intersect = array_intersect(...$x); return end($intersect); } } trait gcdTrait { /** * Get the greatest common divisor. * * @param int ...$x * The first number. * * @return int * The greatest common divisor. */ function gcd(...$x): int { return (new GreatestCommonDivisor())->gcd(...$x); } } class customClass { use gcdTrait; } $foo = new customClass(); echo $foo->gcd(10, 20, 45);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LCmNp
function name:  (null)
number of ops:  11
compiled vars:  !0 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   60     0  E >   DECLARE_CLASS                                            'customclass'
   64     1        NEW                                              $1      'customClass'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $1
   66     4        INIT_METHOD_CALL                                         !0, 'gcd'
          5        SEND_VAL_EX                                              10
          6        SEND_VAL_EX                                              20
          7        SEND_VAL_EX                                              45
          8        DO_FCALL                                      0  $4      
          9        ECHO                                                     $4
         10      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FLCmNp%3A18%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LCmNp
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $i, !1 = $num
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   19     2        MOD                                              ~2      !1, !0
          3        IS_IDENTICAL                                     ~3      ~2, 0
          4      > RETURN                                                   ~3
   20     5*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FLCmNp%3A18%240

Class GreatestCommonDivisor:
Function factors:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LCmNp
function name:  factors
number of ops:  15
compiled vars:  !0 = $num
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   16     1        INIT_FCALL                                               'array_filter'
   17     2        INIT_FCALL                                               'range'
          3        SEND_VAL                                                 1
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $1      
          6        SEND_VAR                                                 $1
   18     7        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FLCmNp%3A18%240'
          8        BIND_LEXICAL                                             ~2, !0
   20     9        SEND_VAL                                                 ~2
         10        DO_ICALL                                         $3      
         11        VERIFY_RETURN_TYPE                                       $3
         12      > RETURN                                                   $3
   22    13*       VERIFY_RETURN_TYPE                                       
         14*     > RETURN                                                   null

End of function factors

Function gcd:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LCmNp
function name:  gcd
number of ops:  21
compiled vars:  !0 = $x, !1 = $intersect
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV_VARIADIC                                    !0      
   35     1        INIT_FCALL                                               'array_map'
          2        FETCH_THIS                                       ~2      
          3        INIT_ARRAY                                       ~3      ~2
          4        ADD_ARRAY_ELEMENT                                ~3      'factors'
          5        SEND_VAL                                                 ~3
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $4      
          8        ASSIGN                                                   !0, $4
   37     9        INIT_FCALL                                               'array_intersect'
         10        SEND_UNPACK                                              !0
         11        CHECK_UNDEF_ARGS                                         
         12        DO_ICALL                                         $6      
         13        ASSIGN                                                   !1, $6
   39    14        INIT_FCALL                                               'end'
         15        SEND_REF                                                 !1
         16        DO_ICALL                                         $8      
         17        VERIFY_RETURN_TYPE                                       $8
         18      > RETURN                                                   $8
   40    19*       VERIFY_RETURN_TYPE                                       
         20*     > RETURN                                                   null

End of function gcd

End of class GreatestCommonDivisor.

Class gcdTrait:
Function gcd:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LCmNp
function name:  gcd
number of ops:  11
compiled vars:  !0 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   RECV_VARIADIC                                    !0      
   56     1        NEW                                              $1      'GreatestCommonDivisor'
          2        DO_FCALL                                      0          
          3        INIT_METHOD_CALL                                         $1, 'gcd'
          4        SEND_UNPACK                                              !0
          5        CHECK_UNDEF_ARGS                                         
          6        DO_FCALL                                      1  $3      
          7        VERIFY_RETURN_TYPE                                       $3
          8      > RETURN                                                   $3
   57     9*       VERIFY_RETURN_TYPE                                       
         10*     > RETURN                                                   null

End of function gcd

End of class gcdTrait.

Class customClass: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
183.18 ms | 1400 KiB | 23 Q