3v4l.org

run code in 300+ PHP versions simultaneously
<?php //Simple math class class Staircase { function __construct($numberOfSteps) { $this->numberOfSteps = $numberOfSteps; } //Returns a closure function buildingNumberOfSteps() { //We can't directly use $this inside closure $thisCopy = $this; return function($storeysNumber) use ($thisCopy) { return $storeysNumber*$thisCopy->numberOfSteps; }; } function buildingNumberOfStepsIncludingBasement() { return function($storeysNumber) { return ($storeysNumber + 1)*$this->numberOfSteps; }; } } $staircase = new Staircase(25); $numberOfStepsToReachRoofTopFromGround = $staircase->buildingNumberOfSteps(); $numberOfStepsToReachRoofTopFromBasement = $staircase->buildingNumberOfStepsIncludingBasement(); echo "5.3 <= PHP < 5.4 only allows me to climb from the ground... the ".$numberOfStepsToReachRoofTopFromGround(5)." steps :( ... "; echo "but with PHP >= 5.4 I can make my way from the basement to the top, climbing the ".$numberOfStepsToReachRoofTopFromBasement(5)." steps ! :D"; ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1WgpU
function name:  (null)
number of ops:  23
compiled vars:  !0 = $staircase, !1 = $numberOfStepsToReachRoofTopFromGround, !2 = $numberOfStepsToReachRoofTopFromBasement
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   NEW                                              $3      'Staircase'
          1        SEND_VAL_EX                                              25
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $3
   30     4        INIT_METHOD_CALL                                         !0, 'buildingNumberOfSteps'
          5        DO_FCALL                                      0  $6      
          6        ASSIGN                                                   !1, $6
   31     7        INIT_METHOD_CALL                                         !0, 'buildingNumberOfStepsIncludingBasement'
          8        DO_FCALL                                      0  $8      
          9        ASSIGN                                                   !2, $8
   33    10        INIT_DYNAMIC_CALL                                        !1
         11        SEND_VAL_EX                                              5
         12        DO_FCALL                                      0  $10     
         13        CONCAT                                           ~11     '5.3+%3C%3D+PHP+%3C+5.4+only+allows+me+to+climb+from+the+ground...+the+', $10
         14        CONCAT                                           ~12     ~11, '+steps+%3A%28+...+'
         15        ECHO                                                     ~12
   34    16        INIT_DYNAMIC_CALL                                        !2
         17        SEND_VAL_EX                                              5
         18        DO_FCALL                                      0  $13     
         19        CONCAT                                           ~14     'but+with+PHP+%3E%3D+5.4+I+can+make+my+way+from+the+basement+to+the+top%2C+climbing+the+', $13
         20        CONCAT                                           ~15     ~14, '+steps+%21+%3AD'
         21        ECHO                                                     ~15
   35    22      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2F1WgpU%3A14%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1WgpU
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $storeysNumber, !1 = $thisCopy
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   16     2        FETCH_OBJ_R                                      ~2      !1, 'numberOfSteps'
          3        MUL                                              ~3      !0, ~2
          4      > RETURN                                                   ~3
   17     5*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F1WgpU%3A14%240

Function %00%7Bclosure%7D%2Fin%2F1WgpU%3A22%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1WgpU
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $storeysNumber
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
   24     1        ADD                                              ~1      !0, 1
          2        FETCH_THIS                                       $2      
          3        FETCH_OBJ_R                                      ~3      $2, 'numberOfSteps'
          4        MUL                                              ~4      ~1, ~3
          5      > RETURN                                                   ~4
   25     6*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F1WgpU%3A22%241

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

End of function __construct

Function buildingnumberofsteps:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1WgpU
function name:  buildingNumberOfSteps
number of ops:  6
compiled vars:  !0 = $thisCopy
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   FETCH_THIS                                       ~1      
          1        ASSIGN                                                   !0, ~1
   14     2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F1WgpU%3A14%240'
          3        BIND_LEXICAL                                             ~3, !0
   17     4      > RETURN                                                   ~3
   18     5*     > RETURN                                                   null

End of function buildingnumberofsteps

Function buildingnumberofstepsincludingbasement:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1WgpU
function name:  buildingNumberOfStepsIncludingBasement
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F1WgpU%3A22%241'
   25     1      > RETURN                                                   ~0
   26     2*     > RETURN                                                   null

End of function buildingnumberofstepsincludingbasement

End of class Staircase.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
172.68 ms | 1399 KiB | 13 Q