3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Monad boxing integer side effects * * @package default * @subpackage default * @author Federico Marani **/ class IntegerBox { /** * undocumented function * * @return void **/ public function __construct($value) { $this->value = $value; $this->isNaN = false; $this->infinite = false; } /** * undocumented function * * @return void **/ public static function identity($unboxedInt) { return new IntegerBox($unboxedInt); } /** * undocumented function * * @return void **/ public static function bind($boxedInt, $function) { $newBox = @$function($boxedInt); if ($newBox->value == null) $newBox->infinite = true; return $newBox; } /** * undocumented function * * @return void **/ public function __toString() { if ($this->isNaN) return "NaN"; if ($this->infinite) return "Infinite"; return strval($this->value); } } // END class IntegerBox $plusOne = function($x) { return IntegerBox::identity($x->value + 1); }; $one = IntegerBox::identity(1); $two = IntegerBox::bind($one, $plusOne); print "$two\n"; $divideByZero = function($x) { return IntegerBox::identity(bcdiv($x->value, 0)); }; $newVal = IntegerBox::bind($one, $divideByZero); print "$newVal\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/A3r6E
function name:  (null)
number of ops:  26
compiled vars:  !0 = $plusOne, !1 = $one, !2 = $two, !3 = $divideByZero, !4 = $newVal
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   DECLARE_CLASS                                            'integerbox'
   60     1        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FA3r6E%3A60%241'
          2        ASSIGN                                                   !0, ~5
   62     3        INIT_STATIC_METHOD_CALL                                  'IntegerBox', 'identity'
          4        SEND_VAL_EX                                              1
          5        DO_FCALL                                      0  $7      
          6        ASSIGN                                                   !1, $7
   64     7        INIT_STATIC_METHOD_CALL                                  'IntegerBox', 'bind'
          8        SEND_VAR_EX                                              !1
          9        SEND_VAR_EX                                              !0
         10        DO_FCALL                                      0  $9      
         11        ASSIGN                                                   !2, $9
   66    12        NOP                                                      
         13        FAST_CONCAT                                      ~11     !2, '%0A'
         14        ECHO                                                     ~11
   68    15        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FA3r6E%3A68%242'
         16        ASSIGN                                                   !3, ~12
   70    17        INIT_STATIC_METHOD_CALL                                  'IntegerBox', 'bind'
         18        SEND_VAR_EX                                              !1
         19        SEND_VAR_EX                                              !3
         20        DO_FCALL                                      0  $14     
         21        ASSIGN                                                   !4, $14
   72    22        NOP                                                      
         23        FAST_CONCAT                                      ~16     !4, '%0A'
         24        ECHO                                                     ~16
         25      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FA3r6E%3A60%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/A3r6E
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   60     0  E >   RECV                                             !0      
          1        INIT_STATIC_METHOD_CALL                                  'IntegerBox', 'identity'
          2        FETCH_OBJ_R                                      ~1      !0, 'value'
          3        ADD                                              ~2      ~1, 1
          4        SEND_VAL_EX                                              ~2
          5        DO_FCALL                                      0  $3      
          6      > RETURN                                                   $3
          7*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FA3r6E%3A60%241

Function %00%7Bclosure%7D%2Fin%2FA3r6E%3A68%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/A3r6E
function name:  {closure}
number of ops:  12
compiled vars:  !0 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   68     0  E >   RECV                                             !0      
          1        INIT_STATIC_METHOD_CALL                                  'IntegerBox', 'identity'
          2        INIT_FCALL_BY_NAME                                       'bcdiv'
          3        CHECK_FUNC_ARG                                           
          4        FETCH_OBJ_FUNC_ARG                               $1      !0, 'value'
          5        SEND_FUNC_ARG                                            $1
          6        SEND_VAL_EX                                              0
          7        DO_FCALL                                      0  $2      
          8        SEND_VAR_NO_REF_EX                                       $2
          9        DO_FCALL                                      0  $3      
         10      > RETURN                                                   $3
         11*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FA3r6E%3A68%242

Class IntegerBox:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/A3r6E
function name:  __construct
number of ops:  8
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   18     1        ASSIGN_OBJ                                               'value'
          2        OP_DATA                                                  !0
   19     3        ASSIGN_OBJ                                               'isNaN'
          4        OP_DATA                                                  <false>
   20     5        ASSIGN_OBJ                                               'infinite'
          6        OP_DATA                                                  <false>
   21     7      > RETURN                                                   null

End of function __construct

Function identity:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/A3r6E
function name:  identity
number of ops:  6
compiled vars:  !0 = $unboxedInt
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
   29     1        NEW                                              $1      'IntegerBox'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4      > RETURN                                                   $1
   30     5*     > RETURN                                                   null

End of function identity

Function bind:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/A3r6E
function name:  bind
number of ops:  15
compiled vars:  !0 = $boxedInt, !1 = $function, !2 = $newBox
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   39     2        BEGIN_SILENCE                                    ~3      
          3        INIT_DYNAMIC_CALL                                        !1
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0  $4      
          6        END_SILENCE                                              ~3
          7        ASSIGN                                                   !2, $4
   40     8        FETCH_OBJ_R                                      ~6      !2, 'value'
          9        IS_EQUAL                                                 ~6, null
         10      > JMPZ                                                     ~7, ->13
   41    11    >   ASSIGN_OBJ                                               !2, 'infinite'
         12        OP_DATA                                                  <true>
   42    13    > > RETURN                                                   !2
   43    14*     > RETURN                                                   null

End of function bind

Function __tostring:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 2, Position 2 = 3
Branch analysis from position: 2
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/A3r6E
function name:  __toString
number of ops:  12
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   52     0  E >   FETCH_OBJ_R                                      ~0      'isNaN'
          1      > JMPZ                                                     ~0, ->3
   53     2    > > RETURN                                                   'NaN'
   54     3    >   FETCH_OBJ_R                                      ~1      'infinite'
          4      > JMPZ                                                     ~1, ->6
   55     5    > > RETURN                                                   'Infinite'
   56     6    >   FETCH_OBJ_R                                      ~2      'value'
          7        CAST                                          6  ~3      ~2
          8        VERIFY_RETURN_TYPE                                       ~3
          9      > RETURN                                                   ~3
   57    10*       VERIFY_RETURN_TYPE                                       
         11*     > RETURN                                                   null

End of function __tostring

End of class IntegerBox.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.04 ms | 943 KiB | 14 Q