3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Invariant{ private $value; private $check; private $description; function __construct($check, $description){ $this->check = $check; $this->description = $description; } function set($value){ $check = $this->check; if($check($value)){ $this->value = $value; }else{ trigger_error("Invariant ".$this->description." violated.", E_USER_ERROR); } } function get(){ return $this->value; } } class A{ protected $a; function __construct(){ $this->a = new Invariant(function($value){return $value > 100;}, '$this->a > 100'); } } class B extends A{ function __construct(){ parent::__construct(); $this->a->set(10); //error $this->a->set(101); //that's ok } } $b = new B();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vjBRG
function name:  (null)
number of ops:  4
compiled vars:  !0 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   NEW                                              $1      'B'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
          3      > RETURN                                                   1

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

End of function __construct

Function set:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 10
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vjBRG
function name:  set
number of ops:  18
compiled vars:  !0 = $value, !1 = $check
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   13     1        FETCH_OBJ_R                                      ~2      'check'
          2        ASSIGN                                                   !1, ~2
   14     3        INIT_DYNAMIC_CALL                                        !1
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0  $4      
          6      > JMPZ                                                     $4, ->10
   15     7    >   ASSIGN_OBJ                                               'value'
          8        OP_DATA                                                  !0
   14     9      > JMP                                                      ->17
   17    10    >   INIT_FCALL                                               'trigger_error'
         11        FETCH_OBJ_R                                      ~6      'description'
         12        CONCAT                                           ~7      'Invariant+', ~6
         13        CONCAT                                           ~8      ~7, '+violated.'
         14        SEND_VAL                                                 ~8
         15        SEND_VAL                                                 256
         16        DO_ICALL                                                 
   19    17    > > RETURN                                                   null

End of function set

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

End of function get

End of class Invariant.

Class A:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vjBRG
function name:  __construct
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   NEW                                              $1      'Invariant'
          1        DECLARE_LAMBDA_FUNCTION                          ~2      [0]
          2        SEND_VAL_EX                                              ~2
          3        SEND_VAL_EX                                              '%24this-%3Ea+%3E+100'
          4        DO_FCALL                                      0          
          5        ASSIGN_OBJ                                               'a'
          6        OP_DATA                                                  $1
   29     7      > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vjBRG
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
          1        IS_SMALLER                                       ~1      100, !0
          2      > RETURN                                                   ~1
          3*     > RETURN                                                   null

End of Dynamic Function 0

End of function __construct

End of class A.

Class B:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vjBRG
function name:  __construct
number of ops:  11
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   INIT_STATIC_METHOD_CALL                                  
          1        DO_FCALL                                      0          
   34     2        FETCH_OBJ_R                                      ~1      'a'
          3        INIT_METHOD_CALL                                         ~1, 'set'
          4        SEND_VAL_EX                                              10
          5        DO_FCALL                                      0          
   35     6        FETCH_OBJ_R                                      ~3      'a'
          7        INIT_METHOD_CALL                                         ~3, 'set'
          8        SEND_VAL_EX                                              101
          9        DO_FCALL                                      0          
   36    10      > RETURN                                                   null

End of function __construct

End of class B.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
136.55 ms | 1003 KiB | 14 Q