3v4l.org

run code in 500+ PHP versions simultaneously
<?php enum FormatOutput: string { case Text = '666777'; case Html = 'html'; } const SOMECONST = 'Const hello'; function SomeFunction() { } $SomeFunctionClosure = function() { }; $SomeFunctionFirstClassCallable = SomeFunction(...); $someFunctionClosureFromCallabe = Closure::fromCallable('SomeFunction'); $arrowFunction = fn($a) => $a; $testcases = [ 666777, '666777', FormatOutput::Text, // For testing purposes: let's see what every type does... SOMECONST, 'abc', -6, 7, -6.7, null, true, false, ['a', 'b', 'c'], [6 => 'six', 7 => 'seven', 67 => 'six seven'], ['a' => 'a', 'b' => 'b', 'c' => 'c', 0 => 'Zero'], function() {}, $SomeFunctionClosure, $SomeFunctionFirstClassCallable, $someFunctionClosureFromCallabe, $arrowFunction, new DateTimeImmutable(), fopen('php://memory', 'w+'), ]; foreach($testcases as $testcase) { echo '--------------[ TESTCASE ]--------------'."\n"; var_dump($testcase); echo "\n"; echo '--- tryFrom()'."\n"; try { $value = FormatOutput::tryFrom($testcase); if ($value !== null) { echo 'Value is '.$value->name.' with value '.$value->value.'.'."\n"; } else { echo 'Value is NULL.'."\n"; } } catch (Throwable $exception) { echo $exception::class, ': ', $exception->getMessage(), "\n"; } echo '--- from()'."\n"; try { $value = FormatOutput::from($testcase); if ($value !== null) { echo 'Value is '.$value->name.' with value '.$value->value.'.'."\n"; } else { echo 'Value is NULL.'."\n"; } } catch (Throwable $exception) { echo $exception::class, ': ', $exception->getMessage(), "\n"; } echo "\n"; echo "\n"; echo "\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 45, Position 2 = 107
Branch analysis from position: 45
2 jumps found. (Code = 78) Position 1 = 46, Position 2 = 107
Branch analysis from position: 46
2 jumps found. (Code = 43) Position 1 = 58, Position 2 = 67
Branch analysis from position: 58
1 jumps found. (Code = 42) Position 1 = 68
Branch analysis from position: 68
1 jumps found. (Code = 42) Position 1 = 77
Branch analysis from position: 77
2 jumps found. (Code = 43) Position 1 = 84, Position 2 = 93
Branch analysis from position: 84
1 jumps found. (Code = 42) Position 1 = 94
Branch analysis from position: 94
1 jumps found. (Code = 42) Position 1 = 103
Branch analysis from position: 103
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
Branch analysis from position: 93
1 jumps found. (Code = 42) Position 1 = 103
Branch analysis from position: 103
Branch analysis from position: 67
1 jumps found. (Code = 42) Position 1 = 77
Branch analysis from position: 77
Branch analysis from position: 107
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 107
Found catch point at position: 69
Branch analysis from position: 69
2 jumps found. (Code = 107) Position 1 = 70, Position 2 = -2
Branch analysis from position: 70
2 jumps found. (Code = 43) Position 1 = 84, Position 2 = 93
Branch analysis from position: 84
Branch analysis from position: 93
Found catch point at position: 95
Branch analysis from position: 95
2 jumps found. (Code = 107) Position 1 = 96, Position 2 = -2
Branch analysis from position: 96
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
filename:       /in/DLGgU
function name:  (null)
number of ops:  109
compiled vars:  !0 = $SomeFunctionClosure, !1 = $SomeFunctionFirstClassCallable, !2 = $someFunctionClosureFromCallabe, !3 = $arrowFunction, !4 = $testcases, !5 = $testcase, !6 = $value, !7 = $exception
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                                'formatoutput'
    9     1        DECLARE_CONST                                                'SOMECONST', 'Const+hello'
   15     2        DECLARE_LAMBDA_FUNCTION                              ~8      [0]
          3        ASSIGN                                                       !0, ~8
   18     4        INIT_FCALL                                                   'somefunction'
          5        CALLABLE_CONVERT                                     ~10     
          6        ASSIGN                                                       !1, ~10
   20     7        INIT_STATIC_METHOD_CALL                                      'Closure', 'fromCallable'
          8        SEND_VAL                                                     'SomeFunction'
          9        DO_FCALL                                          0  $12     
         10        ASSIGN                                                       !2, $12
   22    11        DECLARE_LAMBDA_FUNCTION                              ~14     [1]
         12        ASSIGN                                                       !3, ~14
   25    13        INIT_ARRAY                                           ~16     666777
   26    14        ADD_ARRAY_ELEMENT                                    ~16     '666777'
   27    15        FETCH_CLASS_CONSTANT                                 ~17     'FormatOutput', 'Text'
         16        ADD_ARRAY_ELEMENT                                    ~16     ~17
   30    17        FETCH_CONSTANT                                       ~18     'SOMECONST'
         18        ADD_ARRAY_ELEMENT                                    ~16     ~18
   31    19        ADD_ARRAY_ELEMENT                                    ~16     'abc'
   25    20        ADD_ARRAY_ELEMENT                                    ~16     -6
   33    21        ADD_ARRAY_ELEMENT                                    ~16     7
   25    22        ADD_ARRAY_ELEMENT                                    ~16     -6.7
         23        ADD_ARRAY_ELEMENT                                    ~16     null
         24        ADD_ARRAY_ELEMENT                                    ~16     <true>
         25        ADD_ARRAY_ELEMENT                                    ~16     <false>
         26        ADD_ARRAY_ELEMENT                                    ~16     <array>
         27        ADD_ARRAY_ELEMENT                                    ~16     <array>
         28        ADD_ARRAY_ELEMENT                                    ~16     <array>
   43    29        DECLARE_LAMBDA_FUNCTION                              ~19     [2]
         30        ADD_ARRAY_ELEMENT                                    ~16     ~19
   44    31        ADD_ARRAY_ELEMENT                                    ~16     !0
   45    32        ADD_ARRAY_ELEMENT                                    ~16     !1
   46    33        ADD_ARRAY_ELEMENT                                    ~16     !2
   47    34        ADD_ARRAY_ELEMENT                                    ~16     !3
   49    35        NEW                                                  $20     'DateTimeImmutable'
         36        DO_FCALL                                          0          
         37        ADD_ARRAY_ELEMENT                                    ~16     $20
   50    38        INIT_FCALL                                                   'fopen'
         39        SEND_VAL                                                     'php%3A%2F%2Fmemory'
         40        SEND_VAL                                                     'w%2B'
         41        DO_ICALL                                             $22     
         42        ADD_ARRAY_ELEMENT                                    ~16     $22
   24    43        ASSIGN                                                       !4, ~16
   53    44      > FE_RESET_R                                           $24     !4, ->107
         45    > > FE_FETCH_R                                                   $24, !5, ->107
   54    46    >   ECHO                                                         '--------------%5B+TESTCASE+%5D--------------%0A'
   55    47        INIT_FCALL                                                   'var_dump'
         48        SEND_VAR                                                     !5
         49        DO_ICALL                                                     
   56    50        ECHO                                                         '%0A'
   58    51        ECHO                                                         '---+tryFrom%28%29%0A'
   60    52        INIT_STATIC_METHOD_CALL                                      'FormatOutput', 'tryFrom'
         53        SEND_VAR_EX                                                  !5
         54        DO_FCALL                                          0  $26     
         55        ASSIGN                                                       !6, $26
   61    56        TYPE_CHECK                                      1020          !6
         57      > JMPZ                                                         ~28, ->67
   62    58    >   FETCH_OBJ_R                                          ~29     !6, 'name'
         59        CONCAT                                               ~30     'Value+is+', ~29
         60        CONCAT                                               ~31     ~30, '+with+value+'
         61        FETCH_OBJ_R                                          ~32     !6, 'value'
         62        CONCAT                                               ~33     ~31, ~32
         63        CONCAT                                               ~34     ~33, '.'
         64        CONCAT                                               ~35     ~34, '%0A'
         65        ECHO                                                         ~35
   61    66      > JMP                                                          ->68
   64    67    >   ECHO                                                         'Value+is+NULL.%0A'
         68    > > JMP                                                          ->77
   66    69  E > > CATCH                                           last         'Throwable'
   67    70    >   FETCH_CLASS_NAME                                     ~36     !7
         71        ECHO                                                         ~36
         72        ECHO                                                         '%3A+'
         73        INIT_METHOD_CALL                                             !7, 'getMessage'
         74        DO_FCALL                                          0  $37     
         75        ECHO                                                         $37
         76        ECHO                                                         '%0A'
   70    77    >   ECHO                                                         '---+from%28%29%0A'
   72    78        INIT_STATIC_METHOD_CALL                                      'FormatOutput', 'from'
         79        SEND_VAR_EX                                                  !5
         80        DO_FCALL                                          0  $38     
         81        ASSIGN                                                       !6, $38
   73    82        TYPE_CHECK                                      1020          !6
         83      > JMPZ                                                         ~40, ->93
   74    84    >   FETCH_OBJ_R                                          ~41     !6, 'name'
         85        CONCAT                                               ~42     'Value+is+', ~41
         86        CONCAT                                               ~43     ~42, '+with+value+'
         87        FETCH_OBJ_R                                          ~44     !6, 'value'
         88        CONCAT                                               ~45     ~43, ~44
         89        CONCAT                                               ~46     ~45, '.'
         90        CONCAT                                               ~47     ~46, '%0A'
         91        ECHO                                                         ~47
   73    92      > JMP                                                          ->94
   76    93    >   ECHO                                                         'Value+is+NULL.%0A'
         94    > > JMP                                                          ->103
   78    95  E > > CATCH                                           last         'Throwable'
   79    96    >   FETCH_CLASS_NAME                                     ~48     !7
         97        ECHO                                                         ~48
         98        ECHO                                                         '%3A+'
         99        INIT_METHOD_CALL                                             !7, 'getMessage'
        100        DO_FCALL                                          0  $49     
        101        ECHO                                                         $49
        102        ECHO                                                         '%0A'
   82   103    >   ECHO                                                         '%0A'
   83   104        ECHO                                                         '%0A'
   84   105        ECHO                                                         '%0A'
   53   106      > JMP                                                          ->45
        107    >   FE_FREE                                                      $24
   85   108      > RETURN                                                       1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DLGgU
function name:  {closure:/in/DLGgU:15}
number of ops:  1
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   16     0  E > > RETURN                                                       null

End of Dynamic Function 0

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

End of Dynamic Function 1

Dynamic Function 2
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DLGgU
function name:  {closure:/in/DLGgU:43}
number of ops:  1
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   43     0  E > > RETURN                                                       null

End of Dynamic Function 2

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

End of function somefunction

Class FormatOutput: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
171.27 ms | 2014 KiB | 16 Q