3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Past { private $value; private $pastValues; function __construct($value, array $pastValues = []) { $this->value = $value; $this->pastValues = $pastValues; } function map(callable $fn) { return $this->update($fn($this->value)); } function update($value) { return new Past($value, array_merge($this->pastValues, [$this->value])); } function get() { return array_rand($this->pastValues); } } $answer = new Past(42); $answer = $answer->map(function ($number) { return $number + 1; }); $answer = $answer->update(-3); $answer = $answer->map(function ($number) { return $number * -1; }); $answer = $answer->map(function ($number) { return $number * 3; }); $answer = $answer->update('completely new value, hehehe'); var_dump($answer->get());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GhbOE
function name:  (null)
number of ops:  33
compiled vars:  !0 = $answer
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   NEW                                              $1      'Past'
          1        SEND_VAL_EX                                              42
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $1
   26     4        INIT_METHOD_CALL                                         !0, 'map'
          5        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FGhbOE%3A26%240'
          6        SEND_VAL_EX                                              ~4
          7        DO_FCALL                                      0  $5      
          8        ASSIGN                                                   !0, $5
   27     9        INIT_METHOD_CALL                                         !0, 'update'
         10        SEND_VAL_EX                                              -3
         11        DO_FCALL                                      0  $7      
         12        ASSIGN                                                   !0, $7
   28    13        INIT_METHOD_CALL                                         !0, 'map'
         14        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FGhbOE%3A28%241'
         15        SEND_VAL_EX                                              ~9
         16        DO_FCALL                                      0  $10     
         17        ASSIGN                                                   !0, $10
   29    18        INIT_METHOD_CALL                                         !0, 'map'
         19        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FGhbOE%3A29%242'
         20        SEND_VAL_EX                                              ~12
         21        DO_FCALL                                      0  $13     
         22        ASSIGN                                                   !0, $13
   30    23        INIT_METHOD_CALL                                         !0, 'update'
         24        SEND_VAL_EX                                              'completely+new+value%2C+hehehe'
         25        DO_FCALL                                      0  $15     
         26        ASSIGN                                                   !0, $15
   32    27        INIT_FCALL                                               'var_dump'
         28        INIT_METHOD_CALL                                         !0, 'get'
         29        DO_FCALL                                      0  $17     
         30        SEND_VAR                                                 $17
         31        DO_ICALL                                                 
         32      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FGhbOE%3A26%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GhbOE
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $number
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
          1        ADD                                              ~1      !0, 1
          2      > RETURN                                                   ~1
          3*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FGhbOE%3A26%240

Function %00%7Bclosure%7D%2Fin%2FGhbOE%3A28%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GhbOE
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $number
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
          1        MUL                                              ~1      !0, -1
          2      > RETURN                                                   ~1
          3*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FGhbOE%3A28%241

Function %00%7Bclosure%7D%2Fin%2FGhbOE%3A29%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GhbOE
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $number
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
          1        MUL                                              ~1      !0, 3
          2      > RETURN                                                   ~1
          3*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FGhbOE%3A29%242

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

End of function __construct

Function map:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GhbOE
function name:  map
number of ops:  11
compiled vars:  !0 = $fn
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   13     1        INIT_METHOD_CALL                                         'update'
          2        INIT_DYNAMIC_CALL                                        !0
          3        CHECK_FUNC_ARG                                           
          4        FETCH_OBJ_FUNC_ARG                               $1      'value'
          5        SEND_FUNC_ARG                                            $1
          6        DO_FCALL                                      0  $2      
          7        SEND_VAR_NO_REF_EX                                       $2
          8        DO_FCALL                                      0  $3      
          9      > RETURN                                                   $3
   14    10*     > RETURN                                                   null

End of function map

Function update:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GhbOE
function name:  update
number of ops:  14
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   17     1        NEW                                              $1      'Past'
          2        SEND_VAR_EX                                              !0
          3        INIT_FCALL                                               'array_merge'
          4        FETCH_OBJ_R                                      ~2      'pastValues'
          5        SEND_VAL                                                 ~2
          6        FETCH_OBJ_R                                      ~3      'value'
          7        INIT_ARRAY                                       ~4      ~3
          8        SEND_VAL                                                 ~4
          9        DO_ICALL                                         $5      
         10        SEND_VAR_NO_REF_EX                                       $5
         11        DO_FCALL                                      0          
         12      > RETURN                                                   $1
   18    13*     > RETURN                                                   null

End of function update

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

End of function get

End of class Past.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.08 ms | 1404 KiB | 19 Q