3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface ObjectFeature { public function __construct($object); } interface ObjectHasFeatures { public function addFeature($feature); public function getFeature($class); public function hasFeature($class); } trait HasFeatures { private $_hasfeatures_features = []; public function addFeature($class) { $this->_hasfeatures_features[$class] = new $class($this); } public function getFeature($class) { return $this->_hasfeatures_features[$class]; } public function hasFeature($class) { return isset($this->_hasfeatures_features[$class]); } } class Car implements ObjectHasFeatures { use HasFeatures; private $name; public function __construct($name) { $this->name = $name; } public function getName() { return $this->name; } } class FlyingFeature implements ObjectFeature { private $car; public function __construct($object) { assert($object instanceof Car); $this->car = $object; } public function fly() { echo "*{$this->car->getName()} starts flying*\n"; } } $car = new Car("Notion's Car"); $car->addFeature(FlyingFeature::class); $car->getFeature(FlyingFeature::class)->fly();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Qmm0D
function name:  (null)
number of ops:  15
compiled vars:  !0 = $car
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   DECLARE_CLASS                                            'car'
   27     1        DECLARE_CLASS                                            'flyingfeature'
   33     2        NEW                                              $1      'Car'
          3        SEND_VAL_EX                                              'Notion%27s+Car'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !0, $1
   34     6        INIT_METHOD_CALL                                         !0, 'addFeature'
          7        SEND_VAL_EX                                              'FlyingFeature'
          8        DO_FCALL                                      0          
   36     9        INIT_METHOD_CALL                                         !0, 'getFeature'
         10        SEND_VAL_EX                                              'FlyingFeature'
         11        DO_FCALL                                      0  $5      
         12        INIT_METHOD_CALL                                         $5, 'fly'
         13        DO_FCALL                                      0          
         14      > RETURN                                                   1

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

End of function __construct

End of class ObjectFeature.

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

End of function addfeature

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

End of function getfeature

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

End of function hasfeature

End of class ObjectHasFeatures.

Class HasFeatures:
Function addfeature:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Qmm0D
function name:  addFeature
number of ops:  10
compiled vars:  !0 = $class
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        FETCH_CLASS                                   0  $3      !0
          2        NEW                                              $4      $3
          3        FETCH_THIS                                       $5      
          4        SEND_VAR_EX                                              $5
          5        DO_FCALL                                      0          
          6        FETCH_OBJ_W                                      $1      '_hasfeatures_features'
          7        ASSIGN_DIM                                               $1, !0
          8        OP_DATA                                                  $4
          9      > RETURN                                                   null

End of function addfeature

Function getfeature:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Qmm0D
function name:  getFeature
number of ops:  5
compiled vars:  !0 = $class
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
          1        FETCH_OBJ_R                                      ~1      '_hasfeatures_features'
          2        FETCH_DIM_R                                      ~2      ~1, !0
          3      > RETURN                                                   ~2
          4*     > RETURN                                                   null

End of function getfeature

Function hasfeature:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Qmm0D
function name:  hasFeature
number of ops:  5
compiled vars:  !0 = $class
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
          1        FETCH_OBJ_IS                                     ~1      '_hasfeatures_features'
          2        ISSET_ISEMPTY_DIM_OBJ                         0  ~2      ~1, !0
          3      > RETURN                                                   ~2
          4*     > RETURN                                                   null

End of function hasfeature

End of class HasFeatures.

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

End of function __construct

Function getname:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Qmm0D
function name:  getName
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   FETCH_OBJ_R                                      ~0      'name'
          1      > RETURN                                                   ~0
          2*     > RETURN                                                   null

End of function getname

End of class Car.

Class FlyingFeature:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Qmm0D
function name:  __construct
number of ops:  10
compiled vars:  !0 = $object
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
          1        ASSERT_CHECK                                             
          2        INIT_FCALL                                               'assert'
          3        INSTANCEOF                                       ~1      !0, 'Car'
          4        SEND_VAL                                                 ~1
          5        SEND_VAL                                                 'assert%28%24object+instanceof+Car%29'
          6        DO_ICALL                                                 
          7        ASSIGN_OBJ                                               'car'
          8        OP_DATA                                                  !0
          9      > RETURN                                                   null

End of function __construct

Function fly:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Qmm0D
function name:  fly
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   ROPE_INIT                                     3  ~3      '%2A'
          1        FETCH_OBJ_R                                      ~0      'car'
          2        INIT_METHOD_CALL                                         ~0, 'getName'
          3        DO_FCALL                                      0  $1      
          4        ROPE_ADD                                      1  ~3      ~3, $1
          5        ROPE_END                                      2  ~2      ~3, '+starts+flying%2A%0A'
          6        ECHO                                                     ~2
          7      > RETURN                                                   null

End of function fly

End of class FlyingFeature.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.05 ms | 1019 KiB | 14 Q