3v4l.org

run code in 300+ PHP versions simultaneously
<?php function var_export_filtered_properties(object $obj, Callable $callback, $filter = 0) { $propertiesDef = var_export($obj, true); $propertiesLines = explode(PHP_EOL, $propertiesDef); unset($propertiesLines[array_key_last($propertiesLines)], $propertiesLines[0]); $propertiesLines[] = '];'; array_unshift($propertiesLines, '$properties = ['); $desc = implode($propertiesLines, "\n"); eval($desc); $properties = array_filter($properties, function ($key) use ($callback) { return call_user_func($callback, $key); }, $filter); var_export($properties); } class MyObject { private $a = '1'; private $b = 2; public $c = 'public'; } $obj = new MyObject; var_export_filtered_properties($obj, function ($key) { return $key != 'b'; }, ARRAY_FILTER_USE_KEY);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/e4hV0
function name:  (null)
number of ops:  10
compiled vars:  !0 = $obj
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   NEW                                              $1      'MyObject'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   30     3        INIT_FCALL                                               'var_export_filtered_properties'
          4        SEND_VAR                                                 !0
          5        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fe4hV0%3A30%241'
          6        SEND_VAL                                                 ~4
          7        SEND_VAL                                                 2
          8        DO_FCALL                                      0          
          9      > RETURN                                                   1

Function var_export_filtered_properties:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/e4hV0
function name:  var_export_filtered_properties
number of ops:  42
compiled vars:  !0 = $obj, !1 = $callback, !2 = $filter, !3 = $propertiesDef, !4 = $propertiesLines, !5 = $desc, !6 = $properties
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      0
    4     3        INIT_FCALL                                               'var_export'
          4        SEND_VAR                                                 !0
          5        SEND_VAL                                                 <true>
          6        DO_ICALL                                         $7      
          7        ASSIGN                                                   !3, $7
    6     8        INIT_FCALL                                               'explode'
          9        SEND_VAL                                                 '%0A'
         10        SEND_VAR                                                 !3
         11        DO_ICALL                                         $9      
         12        ASSIGN                                                   !4, $9
    8    13        INIT_FCALL                                               'array_key_last'
         14        SEND_VAR                                                 !4
         15        DO_ICALL                                         $11     
         16        UNSET_DIM                                                !4, $11
         17        UNSET_DIM                                                !4, 0
   10    18        ASSIGN_DIM                                               !4
         19        OP_DATA                                                  '%5D%3B'
   11    20        INIT_FCALL                                               'array_unshift'
         21        SEND_REF                                                 !4
         22        SEND_VAL                                                 '%24properties+%3D+%5B'
         23        DO_ICALL                                                 
   13    24        INIT_FCALL                                               'implode'
         25        SEND_VAR                                                 !4
         26        SEND_VAL                                                 '%0A'
         27        DO_ICALL                                         $14     
         28        ASSIGN                                                   !5, $14
   15    29        INCLUDE_OR_EVAL                                          !5, EVAL
   17    30        INIT_FCALL                                               'array_filter'
         31        SEND_VAR                                                 !6
         32        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fe4hV0%3A17%240'
         33        BIND_LEXICAL                                             ~17, !1
         34        SEND_VAL                                                 ~17
         35        SEND_VAR                                                 !2
         36        DO_ICALL                                         $18     
         37        ASSIGN                                                   !6, $18
   18    38        INIT_FCALL                                               'var_export'
         39        SEND_VAR                                                 !6
         40        DO_ICALL                                                 
   19    41      > RETURN                                                   null

End of function var_export_filtered_properties

Function %00%7Bclosure%7D%2Fin%2Fe4hV0%3A17%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/e4hV0
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $key, !1 = $callback
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        INIT_USER_CALL                                1          'call_user_func', !1
          3        SEND_USER                                                !0
          4        DO_FCALL                                      0  $2      
          5      > RETURN                                                   $2
          6*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Fe4hV0%3A17%240

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

End of function %00%7Bclosure%7D%2Fin%2Fe4hV0%3A30%241

Class MyObject: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
182.89 ms | 1407 KiB | 26 Q