3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types = 1); /** * @template TReturn * @param Closure(): TReturn $closure * @param 'static'|class-string|object $newScope * @return Closure(): TReturn */ function bind(Closure $closure, string|object $newScope = 'static'): Closure { /** @var ?Closure(): TReturn */ $boundClosure = $closure->bindTo(null, $newScope); assert($boundClosure !== null, 'Failed to bind closure.'); return $boundClosure; } final class Vault { public function __construct( private readonly string $secret, ) { } } $vault = new Vault('https://disk.yandex.ru/i/OG-9MXrogsS05g'); $secretAccessor = bind(static fn (): string => $vault->secret, $vault); $secret = $secretAccessor(); var_dump($secret);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K1LUG
function name:  (null)
number of ops:  18
compiled vars:  !0 = $vault, !1 = $secretAccessor, !2 = $secret
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   NEW                                              $3      'Vault'
          1        SEND_VAL_EX                                              'https%3A%2F%2Fdisk.yandex.ru%2Fi%2FOG-9MXrogsS05g'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $3
   30     4        INIT_FCALL                                               'bind'
          5        DECLARE_LAMBDA_FUNCTION                          ~6      [0]
          6        BIND_LEXICAL                                             ~6, !0
          7        SEND_VAL                                                 ~6
          8        SEND_VAR                                                 !0
          9        DO_FCALL                                      0  $7      
         10        ASSIGN                                                   !1, $7
   31    11        INIT_DYNAMIC_CALL                                        !1
         12        DO_FCALL                                      0  $9      
         13        ASSIGN                                                   !2, $9
   32    14        INIT_FCALL                                               'var_dump'
         15        SEND_VAR                                                 !2
         16        DO_ICALL                                                 
         17      > 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/K1LUG
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $vault
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   BIND_STATIC                                              !0
          1        FETCH_OBJ_R                                      ~1      !0, 'secret'
          2        VERIFY_RETURN_TYPE                                       ~1
          3      > RETURN                                                   ~1
          4*       VERIFY_RETURN_TYPE                                       
          5*     > RETURN                                                   null

End of Dynamic Function 0

Function bind:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K1LUG
function name:  bind
number of ops:  17
compiled vars:  !0 = $closure, !1 = $newScope, !2 = $boundClosure
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      'static'
   14     2        INIT_METHOD_CALL                                         !0, 'bindTo'
          3        SEND_VAL_EX                                              null
          4        SEND_VAR_EX                                              !1
          5        DO_FCALL                                      0  $3      
          6        ASSIGN                                                   !2, $3
   16     7        ASSERT_CHECK                                             
          8        INIT_FCALL                                               'assert'
          9        TYPE_CHECK                                  1020  ~5      !2
         10        SEND_VAL                                                 ~5
         11        SEND_VAL                                                 'Failed+to+bind+closure.'
         12        DO_ICALL                                                 
   18    13        VERIFY_RETURN_TYPE                                       !2
         14      > RETURN                                                   !2
   19    15*       VERIFY_RETURN_TYPE                                       
         16*     > RETURN                                                   null

End of function bind

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

End of function __construct

End of class Vault.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
137.27 ms | 1006 KiB | 16 Q