3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Condition { var $causedNext = false; var $cause = null; public function __construct($at, $next = null) { $this->at = $at; $this->next = $next; } public function evalCondition() { $this->causedNext = false; $result = $this->actualEval(); if ($result !== false && $this->next) { $result = $this->next->evalCondition(); if ($result === false) $this->causedNext = true; } return $result; } public function actualEval() { return false; } public function getCause() { return $this->causedNext ? $this->next->getCause() : $this->cause; } } class Condition1 extends Condition { public function __construct($at, $next = null) { parent::__construct($at, $next); $this->cause = "cause 1"; } public function actualEval() { return $this->at->condition1; } } class Condition2 extends Condition { public function __constructor($at, $next = null) { parent::__constructor($at, $next); $this->cause = "cause 2"; } public function actualEval() { return $this->at->condition2; } } class X { var $condition1 = false; var $condition2 = false; public function __construct($c1, $c2) { $this->condition1 = $c1; $this->condition2 = $c2; } protected function check(\Closure $callback) { $condition = new Condition1( $this, new Condition2($this) ); if (!$condition->evalCondition()) { $this->log($condition->getCause()); } else return $callback(); $this->cleanup(); return null; } public function doSomething() { $this->check($this->reallyDoSomething); } public function reallyDoSomething() { echo "! Done!"; } public function cleanup() { echo "* cleanup...\n"; } public function log($str) { echo "> $str\n"; } } echo "f, f\n"; $x = new X(false, false); $x->doSomething(); echo "f, t\n"; $x = new X(false, true); $x->doSomething(); echo "t, f\n"; $x = new X(true, false); $x->doSomething(); echo "t, t\n"; $x = new X(true, true); $x->doSomething();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mZTMO
function name:  (null)
number of ops:  33
compiled vars:  !0 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  103     0  E >   ECHO                                                     'f%2C+f%0A'
  104     1        NEW                                              $1      'X'
          2        SEND_VAL_EX                                              <false>
          3        SEND_VAL_EX                                              <false>
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !0, $1
  105     6        INIT_METHOD_CALL                                         !0, 'doSomething'
          7        DO_FCALL                                      0          
  107     8        ECHO                                                     'f%2C+t%0A'
  108     9        NEW                                              $5      'X'
         10        SEND_VAL_EX                                              <false>
         11        SEND_VAL_EX                                              <true>
         12        DO_FCALL                                      0          
         13        ASSIGN                                                   !0, $5
  109    14        INIT_METHOD_CALL                                         !0, 'doSomething'
         15        DO_FCALL                                      0          
  111    16        ECHO                                                     't%2C+f%0A'
  112    17        NEW                                              $9      'X'
         18        SEND_VAL_EX                                              <true>
         19        SEND_VAL_EX                                              <false>
         20        DO_FCALL                                      0          
         21        ASSIGN                                                   !0, $9
  113    22        INIT_METHOD_CALL                                         !0, 'doSomething'
         23        DO_FCALL                                      0          
  115    24        ECHO                                                     't%2C+t%0A'
  116    25        NEW                                              $13     'X'
         26        SEND_VAL_EX                                              <true>
         27        SEND_VAL_EX                                              <true>
         28        DO_FCALL                                      0          
         29        ASSIGN                                                   !0, $13
  117    30        INIT_METHOD_CALL                                         !0, 'doSomething'
         31        DO_FCALL                                      0          
         32      > RETURN                                                   1

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

End of function __construct

Function evalcondition:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 18
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 18
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
Branch analysis from position: 18
Branch analysis from position: 9
filename:       /in/mZTMO
function name:  evalCondition
number of ops:  20
compiled vars:  !0 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   ASSIGN_OBJ                                               'causedNext'
          1        OP_DATA                                                  <false>
   15     2        INIT_METHOD_CALL                                         'actualEval'
          3        DO_FCALL                                      0  $2      
          4        ASSIGN                                                   !0, $2
   16     5        TYPE_CHECK                                  1018  ~4      !0
          6      > JMPZ_EX                                          ~4      ~4, ->9
          7    >   FETCH_OBJ_R                                      ~5      'next'
          8        BOOL                                             ~4      ~5
          9    > > JMPZ                                                     ~4, ->18
   17    10    >   FETCH_OBJ_R                                      ~6      'next'
         11        INIT_METHOD_CALL                                         ~6, 'evalCondition'
         12        DO_FCALL                                      0  $7      
         13        ASSIGN                                                   !0, $7
   18    14        TYPE_CHECK                                    4          !0
         15      > JMPZ                                                     ~9, ->18
   19    16    >   ASSIGN_OBJ                                               'causedNext'
         17        OP_DATA                                                  <true>
   21    18    > > RETURN                                                   !0
   22    19*     > RETURN                                                   null

End of function evalcondition

Function actualeval:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mZTMO
function name:  actualEval
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E > > RETURN                                                   <false>
   26     1*     > RETURN                                                   null

End of function actualeval

Function getcause:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 2, Position 2 = 7
Branch analysis from position: 2
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mZTMO
function name:  getCause
number of ops:  11
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   FETCH_OBJ_R                                      ~0      'causedNext'
          1      > JMPZ                                                     ~0, ->7
          2    >   FETCH_OBJ_R                                      ~1      'next'
          3        INIT_METHOD_CALL                                         ~1, 'getCause'
          4        DO_FCALL                                      0  $2      
          5        QM_ASSIGN                                        ~3      $2
          6      > JMP                                                      ->9
          7    >   FETCH_OBJ_R                                      ~4      'cause'
          8        QM_ASSIGN                                        ~3      ~4
          9    > > RETURN                                                   ~3
   30    10*     > RETURN                                                   null

End of function getcause

End of class Condition.

Class Condition1:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mZTMO
function name:  __construct
number of ops:  9
compiled vars:  !0 = $at, !1 = $next
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
   37     2        INIT_STATIC_METHOD_CALL                                  
          3        SEND_VAR_EX                                              !0
          4        SEND_VAR_EX                                              !1
          5        DO_FCALL                                      0          
   38     6        ASSIGN_OBJ                                               'cause'
          7        OP_DATA                                                  'cause+1'
   39     8      > RETURN                                                   null

End of function __construct

Function actualeval:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mZTMO
function name:  actualEval
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   FETCH_OBJ_R                                      ~0      'at'
          1        FETCH_OBJ_R                                      ~1      ~0, 'condition1'
          2      > RETURN                                                   ~1
   43     3*     > RETURN                                                   null

End of function actualeval

Function evalcondition:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 18
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 18
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
Branch analysis from position: 18
Branch analysis from position: 9
filename:       /in/mZTMO
function name:  evalCondition
number of ops:  20
compiled vars:  !0 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   ASSIGN_OBJ                                               'causedNext'
          1        OP_DATA                                                  <false>
   15     2        INIT_METHOD_CALL                                         'actualEval'
          3        DO_FCALL                                      0  $2      
          4        ASSIGN                                                   !0, $2
   16     5        TYPE_CHECK                                  1018  ~4      !0
          6      > JMPZ_EX                                          ~4      ~4, ->9
          7    >   FETCH_OBJ_R                                      ~5      'next'
          8        BOOL                                             ~4      ~5
          9    > > JMPZ                                                     ~4, ->18
   17    10    >   FETCH_OBJ_R                                      ~6      'next'
         11        INIT_METHOD_CALL                                         ~6, 'evalCondition'
         12        DO_FCALL                                      0  $7      
         13        ASSIGN                                                   !0, $7
   18    14        TYPE_CHECK                                    4          !0
         15      > JMPZ                                                     ~9, ->18
   19    16    >   ASSIGN_OBJ                                               'causedNext'
         17        OP_DATA                                                  <true>
   21    18    > > RETURN                                                   !0
   22    19*     > RETURN                                                   null

End of function evalcondition

Function getcause:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 2, Position 2 = 7
Branch analysis from position: 2
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mZTMO
function name:  getCause
number of ops:  11
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   FETCH_OBJ_R                                      ~0      'causedNext'
          1      > JMPZ                                                     ~0, ->7
          2    >   FETCH_OBJ_R                                      ~1      'next'
          3        INIT_METHOD_CALL                                         ~1, 'getCause'
          4        DO_FCALL                                      0  $2      
          5        QM_ASSIGN                                        ~3      $2
          6      > JMP                                                      ->9
          7    >   FETCH_OBJ_R                                      ~4      'cause'
          8        QM_ASSIGN                                        ~3      ~4
          9    > > RETURN                                                   ~3
   30    10*     > RETURN                                                   null

End of function getcause

End of class Condition1.

Class Condition2:
Function __constructor:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mZTMO
function name:  __constructor
number of ops:  9
compiled vars:  !0 = $at, !1 = $next
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
   50     2        INIT_STATIC_METHOD_CALL                                  '__constructor'
          3        SEND_VAR_EX                                              !0
          4        SEND_VAR_EX                                              !1
          5        DO_FCALL                                      0          
   51     6        ASSIGN_OBJ                                               'cause'
          7        OP_DATA                                                  'cause+2'
   52     8      > RETURN                                                   null

End of function __constructor

Function actualeval:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mZTMO
function name:  actualEval
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   55     0  E >   FETCH_OBJ_R                                      ~0      'at'
          1        FETCH_OBJ_R                                      ~1      ~0, 'condition2'
          2      > RETURN                                                   ~1
   56     3*     > RETURN                                                   null

End of function actualeval

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

End of function __construct

Function evalcondition:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 18
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 18
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
Branch analysis from position: 18
Branch analysis from position: 9
filename:       /in/mZTMO
function name:  evalCondition
number of ops:  20
compiled vars:  !0 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   ASSIGN_OBJ                                               'causedNext'
          1        OP_DATA                                                  <false>
   15     2        INIT_METHOD_CALL                                         'actualEval'
          3        DO_FCALL                                      0  $2      
          4        ASSIGN                                                   !0, $2
   16     5        TYPE_CHECK                                  1018  ~4      !0
          6      > JMPZ_EX                                          ~4      ~4, ->9
          7    >   FETCH_OBJ_R                                      ~5      'next'
          8        BOOL                                             ~4      ~5
          9    > > JMPZ                                                     ~4, ->18
   17    10    >   FETCH_OBJ_R                                      ~6      'next'
         11        INIT_METHOD_CALL                                         ~6, 'evalCondition'
         12        DO_FCALL                                      0  $7      
         13        ASSIGN                                                   !0, $7
   18    14        TYPE_CHECK                                    4          !0
         15      > JMPZ                                                     ~9, ->18
   19    16    >   ASSIGN_OBJ                                               'causedNext'
         17        OP_DATA                                                  <true>
   21    18    > > RETURN                                                   !0
   22    19*     > RETURN                                                   null

End of function evalcondition

Function getcause:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 2, Position 2 = 7
Branch analysis from position: 2
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mZTMO
function name:  getCause
number of ops:  11
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   FETCH_OBJ_R                                      ~0      'causedNext'
          1      > JMPZ                                                     ~0, ->7
          2    >   FETCH_OBJ_R                                      ~1      'next'
          3        INIT_METHOD_CALL                                         ~1, 'getCause'
          4        DO_FCALL                                      0  $2      
          5        QM_ASSIGN                                        ~3      $2
          6      > JMP                                                      ->9
          7    >   FETCH_OBJ_R                                      ~4      'cause'
          8        QM_ASSIGN                                        ~3      ~4
          9    > > RETURN                                                   ~3
   30    10*     > RETURN                                                   null

End of function getcause

End of class Condition2.

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

End of function __construct

Function check:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 21
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mZTMO
function name:  check
number of ops:  28
compiled vars:  !0 = $callback, !1 = $condition
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   70     0  E >   RECV                                             !0      
   71     1        NEW                                              $2      'Condition1'
   72     2        FETCH_THIS                                       $3      
          3        SEND_VAR_EX                                              $3
   73     4        NEW                                              $4      'Condition2'
          5        FETCH_THIS                                       $5      
          6        SEND_VAR_EX                                              $5
          7        DO_FCALL                                      0          
          8        SEND_VAR_NO_REF_EX                                       $4
          9        DO_FCALL                                      0          
   71    10        ASSIGN                                                   !1, $2
   76    11        INIT_METHOD_CALL                                         !1, 'evalCondition'
         12        DO_FCALL                                      0  $9      
         13        BOOL_NOT                                         ~10     $9
         14      > JMPZ                                                     ~10, ->21
   77    15    >   INIT_METHOD_CALL                                         'log'
         16        INIT_METHOD_CALL                                         !1, 'getCause'
         17        DO_FCALL                                      0  $11     
         18        SEND_VAR_NO_REF_EX                                       $11
         19        DO_FCALL                                      0          
         20      > JMP                                                      ->24
   79    21    >   INIT_DYNAMIC_CALL                                        !0
         22        DO_FCALL                                      0  $13     
         23      > RETURN                                                   $13
   81    24    >   INIT_METHOD_CALL                                         'cleanup'
         25        DO_FCALL                                      0          
   82    26      > RETURN                                                   null
   83    27*     > RETURN                                                   null

End of function check

Function dosomething:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mZTMO
function name:  doSomething
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   86     0  E >   INIT_METHOD_CALL                                         'check'
          1        CHECK_FUNC_ARG                                           
          2        FETCH_OBJ_FUNC_ARG                               $0      'reallyDoSomething'
          3        SEND_FUNC_ARG                                            $0
          4        DO_FCALL                                      0          
   87     5      > RETURN                                                   null

End of function dosomething

Function reallydosomething:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mZTMO
function name:  reallyDoSomething
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   90     0  E >   ECHO                                                     '%21+Done%21'
   91     1      > RETURN                                                   null

End of function reallydosomething

Function cleanup:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mZTMO
function name:  cleanup
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   94     0  E >   ECHO                                                     '%2A+cleanup...%0A'
   95     1      > RETURN                                                   null

End of function cleanup

Function log:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mZTMO
function name:  log
number of ops:  6
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   97     0  E >   RECV                                             !0      
   98     1        ROPE_INIT                                     3  ~2      '%3E+'
          2        ROPE_ADD                                      1  ~2      ~2, !0
          3        ROPE_END                                      2  ~1      ~2, '%0A'
          4        ECHO                                                     ~1
   99     5      > RETURN                                                   null

End of function log

End of class X.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.38 ms | 1419 KiB | 13 Q