3v4l.org

run code in 500+ PHP versions simultaneously
<?php class Outer { private static $inner = null; private function __construct() { } private static function ensure() { if ( isset( self::$inner ) ) { return; } self::$inner = new class () { private $html = ''; public static function wrap( $html ) { $self = new self(); $self->html = $html; return $self; } public static function unwrap( $self ) { return $self->html; } }; } public static function wrap( $html ) { self::ensure(); return self::$inner::wrap( $html ); } public static function unwrap( $self ) { return $self instanceof self::$inner ? self::$inner::unwrap( $self ) : $self; } } $wrapped = Outer::wrap( '<div>just <script>a test</script> some HTML</div>' ); var_dump( $wrapped ); var_dump( Outer::unwrap( $wrapped ) ); // Can’t call this from outside `Outer` because of the anonymous class. // var_dump( $wrapped->unwrap() ); // It’s still possible to call via a self-reference, but that’s awkward and will stand out. var_dump( $wrapped::unwrap( $wrapped ) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aOOj7
function name:  (null)
number of ops:  21
compiled vars:  !0 = $wrapped
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   45     0  E >   INIT_STATIC_METHOD_CALL                                      'Outer', 'wrap'
          1        SEND_VAL                                                     '%3Cdiv%3Ejust+%3Cscript%3Ea+test%3C%2Fscript%3E+some+HTML%3C%2Fdiv%3E'
          2        DO_FCALL                                          0  $1      
          3        ASSIGN                                                       !0, $1
   46     4        INIT_FCALL                                                   'var_dump'
          5        SEND_VAR                                                     !0
          6        DO_ICALL                                                     
   47     7        INIT_FCALL                                                   'var_dump'
          8        INIT_STATIC_METHOD_CALL                                      'Outer', 'unwrap'
          9        SEND_VAR                                                     !0
         10        DO_FCALL                                          0  $4      
         11        SEND_VAR                                                     $4
         12        DO_ICALL                                                     
   53    13        INIT_FCALL                                                   'var_dump'
         14        FETCH_CLASS                                       0  $6      !0
         15        INIT_STATIC_METHOD_CALL                                      $6, 'unwrap'
         16        SEND_VAR_EX                                                  !0
         17        DO_FCALL                                          0  $7      
         18        SEND_VAR                                                     $7
         19        DO_ICALL                                                     
         20      > RETURN                                                       1

Class class@anonymous:
Function wrap:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aOOj7
function name:  wrap
number of ops:  8
compiled vars:  !0 = $html, !1 = $self
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   19     0  E >   RECV                                                 !0      
   20     1        NEW                              self                $2      
          2        DO_FCALL                                          0          
          3        ASSIGN                                                       !1, $2
   21     4        ASSIGN_OBJ                                                   !1, 'html'
          5        OP_DATA                                                      !0
   23     6      > RETURN                                                       !1
   24     7*     > RETURN                                                       null

End of function wrap

Function unwrap:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aOOj7
function name:  unwrap
number of ops:  4
compiled vars:  !0 = $self
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   26     0  E >   RECV                                                 !0      
   27     1        FETCH_OBJ_R                                          ~1      !0, 'html'
          2      > RETURN                                                       ~1
   28     3*     > RETURN                                                       null

End of function unwrap

End of class class@anonymous.

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

End of function __construct

Function ensure:
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
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aOOj7
function name:  ensure
number of ops:  9
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   11     0  E >   ISSET_ISEMPTY_STATIC_PROP                                    'inner'
          1      > JMPZ                                                         ~0, ->3
   12     2    > > RETURN                                                       null
   15     3    >   DECLARE_ANON_CLASS                                   <unknown> 
          4        NEW                                                  $3      $2
          5        DO_FCALL                                          0          
          6        ASSIGN_STATIC_PROP                                           'inner'
          7        OP_DATA                                                      $3
   30     8      > RETURN                                                       null

End of function ensure

Function wrap:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aOOj7
function name:  wrap
number of ops:  10
compiled vars:  !0 = $html
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   32     0  E >   RECV                                                 !0      
   33     1        INIT_STATIC_METHOD_CALL                                      'ensure'
          2        DO_FCALL                                          0          
   35     3        FETCH_STATIC_PROP_R              unknown             ~2      'inner'
          4        FETCH_CLASS                                       0  $3      ~2
          5        INIT_STATIC_METHOD_CALL                                      $3, 'wrap'
          6        SEND_VAR_EX                                                  !0
          7        DO_FCALL                                          0  $4      
          8      > RETURN                                                       $4
   36     9*     > RETURN                                                       null

End of function wrap

Function unwrap:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 12
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aOOj7
function name:  unwrap
number of ops:  15
compiled vars:  !0 = $self
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   38     0  E >   RECV                                                 !0      
   39     1        FETCH_STATIC_PROP_R              unknown             ~1      'inner'
          2        FETCH_CLASS                                       0  $2      ~1
          3        INSTANCEOF                                                   !0, $2
          4      > JMPZ                                                         ~3, ->12
   40     5    >   FETCH_STATIC_PROP_R              unknown             ~4      'inner'
          6        FETCH_CLASS                                       0  $5      ~4
          7        INIT_STATIC_METHOD_CALL                                      $5, 'unwrap'
          8        SEND_VAR_EX                                                  !0
          9        DO_FCALL                                          0  $6      
         10        QM_ASSIGN                                            ~7      $6
         11      > JMP                                                          ->13
   41    12    >   QM_ASSIGN                                            ~7      !0
         13    > > RETURN                                                       ~7
   42    14*     > RETURN                                                       null

End of function unwrap

End of class Outer.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
115.54 ms | 498 KiB | 10 Q