3v4l.org

run code in 500+ PHP versions simultaneously
<?php trait CalculatesArea { private $pi = 3.1416; private function rectangularArea(): float { return $this->a * $this->b; } private function ellipticArea(): float { return $this->a * $this->b * $this->pi; } } abstract class Shape { use CalculatesArea; public function __construct(protected float $a, protected float $b) {} public function area(): ?float { if ($this instanceof Rectangle) { return $this->rectangularArea(); } if ($this instanceof Ellipse) { return $this->ellipticArea(); } return null; } } class Rectangle extends Shape {} class Ellipse extends Shape {} var_dump( (new Rectangle(3, 4))->area(), (new Ellipse(1.3, 3.8))->area(), );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/l3RTl
function name:  (null)
number of ops:  20
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   18     0  E >   DECLARE_CLASS                                                'shape'
   38     1        DECLARE_CLASS                                                'rectangle', 'shape'
   40     2        DECLARE_CLASS                                                'ellipse', 'shape'
   42     3        INIT_FCALL                                                   'var_dump'
   43     4        NEW                                                  $0      'Rectangle'
          5        SEND_VAL_EX                                                  3
          6        SEND_VAL_EX                                                  4
          7        DO_FCALL                                          0          
          8        INIT_METHOD_CALL                                             $0, 'area'
          9        DO_FCALL                                          0  $2      
         10        SEND_VAR                                                     $2
   44    11        NEW                                                  $3      'Ellipse'
         12        SEND_VAL_EX                                                  1.3
         13        SEND_VAL_EX                                                  3.8
         14        DO_FCALL                                          0          
         15        INIT_METHOD_CALL                                             $3, 'area'
         16        DO_FCALL                                          0  $5      
         17        SEND_VAR                                                     $5
   42    18        DO_ICALL                                                     
   45    19      > RETURN                                                       1

Class CalculatesArea:
Function rectangulararea:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/l3RTl
function name:  rectangularArea
number of ops:  7
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    9     0  E >   FETCH_OBJ_R                                          ~0      'a'
          1        FETCH_OBJ_R                                          ~1      'b'
          2        MUL                                                  ~2      ~0, ~1
          3        VERIFY_RETURN_TYPE                                           ~2
          4      > RETURN                                                       ~2
   10     5*       VERIFY_RETURN_TYPE                                           
          6*     > RETURN                                                       null

End of function rectangulararea

Function ellipticarea:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/l3RTl
function name:  ellipticArea
number of ops:  9
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   14     0  E >   FETCH_OBJ_R                                          ~0      'a'
          1        FETCH_OBJ_R                                          ~1      'b'
          2        MUL                                                  ~2      ~0, ~1
          3        FETCH_OBJ_R                                          ~3      'pi'
          4        MUL                                                  ~4      ~2, ~3
          5        VERIFY_RETURN_TYPE                                           ~4
          6      > RETURN                                                       ~4
   15     7*       VERIFY_RETURN_TYPE                                           
          8*     > RETURN                                                       null

End of function ellipticarea

End of class CalculatesArea.

Class Shape:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/l3RTl
function name:  __construct
number of ops:  7
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   22     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        ASSIGN_OBJ                                                   'a'
          3        OP_DATA                                                      !0
          4        ASSIGN_OBJ                                                   'b'
          5        OP_DATA                                                      !1
          6      > RETURN                                                       null

End of function __construct

Function area:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 14
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/l3RTl
function name:  area
number of ops:  17
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   26     0  E >   FETCH_THIS                                           ~0      
          1        INSTANCEOF                                                   ~0, 'Rectangle'
          2      > JMPZ                                                         ~1, ->7
   27     3    >   INIT_METHOD_CALL                                             'rectangularArea'
          4        DO_FCALL                                          0  $2      
          5        VERIFY_RETURN_TYPE                                           $2
          6      > RETURN                                                       $2
   30     7    >   FETCH_THIS                                           ~3      
          8        INSTANCEOF                                                   ~3, 'Ellipse'
          9      > JMPZ                                                         ~4, ->14
   31    10    >   INIT_METHOD_CALL                                             'ellipticArea'
         11        DO_FCALL                                          0  $5      
         12        VERIFY_RETURN_TYPE                                           $5
         13      > RETURN                                                       $5
   34    14    > > RETURN                                                       null
   35    15*       VERIFY_RETURN_TYPE                                           
         16*     > RETURN                                                       null

End of function area

End of class Shape.

Class Rectangle: [no user functions]
Class Ellipse: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
161.43 ms | 1464 KiB | 14 Q