3v4l.org

run code in 300+ PHP versions simultaneously
<?php function sanitize_term($data) { return $data; } #[AllowDynamicProperties] class WP_Term { public $term_id; public $name = ''; public $slug = ''; public $term_group = ''; public $term_taxonomy_id = 0; public $taxonomy = ''; public $description = ''; public $parent = 0; public $count = 0; public $filter = 'raw'; // public $data; // public $object_id; // // Added by wp_tag_cloud(). // public $id; // public $link = ''; // // Added by _make_cat_compat(). // public $cat_ID; // public $category_count; // public $category_description; // public $cat_name; // public $category_nicename; // public $category_parent; public function to_array() { return get_object_vars( $this ); } public function __get( $name ) { switch ( $name ) { case 'data': $data = new stdClass(); // db columns for the terms and term_taxonomy tables. $columns = array( 'term_id', 'name', 'slug', 'term_group', 'term_taxonomy_id', 'taxonomy', 'description', 'parent', 'count' ); foreach ( $columns as $column ) { $data->{$column} = isset( $this->{$column} ) ? $this->{$column} : null; } // adds the 'filter' field. return sanitize_term( $data, $data->taxonomy, 'raw' ); }; } } class Tester { private $term; private $dyanmic_properties = array( 'data', 'link', 'unknown'); public function __construct($term) { $this->term = $term; } public function test() { $this->test_isset('before'); $this->test_get(); $this->test_set(); $this->test_isset('after'); $this->test_unset(); $this->dump_to_array(); } private function test_get() { $term_data = (array) $this->term->data; } private function test_isset($message) { echo "\nTesting isset() $message set/get..\n"; foreach ($this->dyanmic_properties as $prop) { printf( "\tWP_Term::$%s: %s\n", $prop, isset($this->term->$prop) ? 'True' : 'False' ); } } private function test_set() { $this->term->unknown = 'unknown dynamic property'; $this->term->link = 'https://example.com/'; } private function test_unset() { unset($this->term->link); printf( "\nTesting unset(): Did WP_Term::\$link unset? \n%s\n", isset( $this->term->link) ? 'No' : 'Yes' ); } private function dump_to_array() { $via_to_array = $this->term->to_array(); $via_to_array_props = array_keys($via_to_array); $via_typecast = (array) $this->term; $via_typecast_props = array_keys($via_typecast); $diff1 = array_diff($via_to_array_props, $via_typecast_props); $diff2 = array_diff($via_typecast_props, $via_to_array_props); echo "\n\nAre the results the same between WP_Term::to_array() and(array) \$term?\n"; if (empty($diff1) && empty($diff2)) { echo "Yes\n"; } else { echo "No\n"; if (! empty($diff1)) { echo "\nWP_Term::to_array() vs (array) \$term\n"; var_dump($diff1); } if (! empty($diff2)) { echo "\n(array) \$term vs WP_Term::to_array()\n"; var_dump($diff2); } } } } (new Tester( new WP_Term() ) )->test();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6F0nJ
function name:  (null)
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  128     0  E >   NEW                                              $0      'Tester'
          1        NEW                                              $1      'WP_Term'
          2        DO_FCALL                                      0          
          3        SEND_VAR_NO_REF_EX                                       $1
          4        DO_FCALL                                      0          
          5        INIT_METHOD_CALL                                         $0, 'test'
          6        DO_FCALL                                      0          
          7      > RETURN                                                   1

Function sanitize_term:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6F0nJ
function name:  sanitize_term
number of ops:  3
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1      > RETURN                                                   !0
    5     2*     > RETURN                                                   null

End of function sanitize_term

Class WP_Term:
Function to_array:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6F0nJ
function name:  to_array
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   INIT_FCALL                                               'get_object_vars'
          1        FETCH_THIS                                       ~0      
          2        SEND_VAL                                                 ~0
          3        DO_ICALL                                         $1      
          4      > RETURN                                                   $1
   36     5*     > RETURN                                                   null

End of function to_array

Function __get:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 44) Position 1 = 3, Position 2 = 4
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 19
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 19
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 15
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/6F0nJ
function name:  __get
number of ops:  28
compiled vars:  !0 = $name, !1 = $data, !2 = $columns, !3 = $column
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV                                             !0      
   40     1        IS_EQUAL                                                 !0, 'data'
          2      > JMPNZ                                                    ~4, ->4
          3    > > JMP                                                      ->27
   41     4    >   NEW                                              $5      'stdClass'
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !1, $5
   43     7        ASSIGN                                                   !2, <array>
   44     8      > FE_RESET_R                                       $9      !2, ->19
          9    > > FE_FETCH_R                                               $9, !3, ->19
   45    10    >   ISSET_ISEMPTY_PROP_OBJ                                   !3
         11      > JMPZ                                                     ~11, ->15
         12    >   FETCH_OBJ_R                                      ~12     !3
         13        QM_ASSIGN                                        ~13     ~12
         14      > JMP                                                      ->16
         15    >   QM_ASSIGN                                        ~13     null
         16    >   ASSIGN_OBJ                                               !1, !3
         17        OP_DATA                                                  ~13
   44    18      > JMP                                                      ->9
         19    >   FE_FREE                                                  $9
   49    20        INIT_FCALL                                               'sanitize_term'
         21        SEND_VAR                                                 !1
         22        FETCH_OBJ_R                                      ~14     !1, 'taxonomy'
         23        SEND_VAL                                                 ~14
         24        SEND_VAL                                                 'raw'
         25        DO_FCALL                                      0  $15     
         26      > RETURN                                                   $15
   51    27    > > RETURN                                                   null

End of function __get

End of class WP_Term.

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

End of function __construct

Function test:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6F0nJ
function name:  test
number of ops:  15
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   63     0  E >   INIT_METHOD_CALL                                         'test_isset'
          1        SEND_VAL_EX                                              'before'
          2        DO_FCALL                                      0          
   65     3        INIT_METHOD_CALL                                         'test_get'
          4        DO_FCALL                                      0          
   66     5        INIT_METHOD_CALL                                         'test_set'
          6        DO_FCALL                                      0          
   68     7        INIT_METHOD_CALL                                         'test_isset'
          8        SEND_VAL_EX                                              'after'
          9        DO_FCALL                                      0          
   70    10        INIT_METHOD_CALL                                         'test_unset'
         11        DO_FCALL                                      0          
   72    12        INIT_METHOD_CALL                                         'dump_to_array'
         13        DO_FCALL                                      0          
   73    14      > RETURN                                                   null

End of function test

Function test_get:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6F0nJ
function name:  test_get
number of ops:  5
compiled vars:  !0 = $term_data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   76     0  E >   FETCH_OBJ_R                                      ~1      'term'
          1        FETCH_OBJ_R                                      ~2      ~1, 'data'
          2        CAST                                          7  ~3      ~2
          3        ASSIGN                                                   !0, ~3
   77     4      > RETURN                                                   null

End of function test_get

Function test_isset:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 20
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 20
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 16
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
filename:       /in/6F0nJ
function name:  test_isset
number of ops:  22
compiled vars:  !0 = $message, !1 = $prop
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   79     0  E >   RECV                                             !0      
   80     1        ROPE_INIT                                     3  ~3      '%0ATesting+isset%28%29+'
          2        ROPE_ADD                                      1  ~3      ~3, !0
          3        ROPE_END                                      2  ~2      ~3, '+set%2Fget..%0A'
          4        ECHO                                                     ~2
   82     5        FETCH_OBJ_R                                      ~5      'dyanmic_properties'
          6      > FE_RESET_R                                       $6      ~5, ->20
          7    > > FE_FETCH_R                                               $6, !1, ->20
   83     8    >   INIT_FCALL                                               'printf'
          9        SEND_VAL                                                 '%09WP_Term%3A%3A%24%25s%3A+%25s%0A'
         10        SEND_VAR                                                 !1
         11        FETCH_OBJ_IS                                     ~7      'term'
         12        ISSET_ISEMPTY_PROP_OBJ                                   ~7, !1
         13      > JMPZ                                                     ~8, ->16
         14    >   QM_ASSIGN                                        ~9      'True'
         15      > JMP                                                      ->17
         16    >   QM_ASSIGN                                        ~9      'False'
         17    >   SEND_VAL                                                 ~9
         18        DO_ICALL                                                 
   82    19      > JMP                                                      ->7
         20    >   FE_FREE                                                  $6
   85    21      > RETURN                                                   null

End of function test_isset

Function test_set:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6F0nJ
function name:  test_set
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   88     0  E >   FETCH_OBJ_W                                      $0      'term'
          1        ASSIGN_OBJ                                               $0, 'unknown'
          2        OP_DATA                                                  'unknown+dynamic+property'
   89     3        FETCH_OBJ_W                                      $2      'term'
          4        ASSIGN_OBJ                                               $2, 'link'
          5        OP_DATA                                                  'https%3A%2F%2Fexample.com%2F'
   90     6      > RETURN                                                   null

End of function test_set

Function test_unset:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6F0nJ
function name:  test_unset
number of ops:  13
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   93     0  E >   FETCH_OBJ_UNSET                                  $0      'term'
          1        UNSET_OBJ                                                $0, 'link'
   95     2        INIT_FCALL                                               'printf'
   96     3        SEND_VAL                                                 '%0ATesting+unset%28%29%3A+Did+WP_Term%3A%3A%24link+unset%3F+%0A%25s%0A'
   97     4        FETCH_OBJ_IS                                     ~1      'term'
          5        ISSET_ISEMPTY_PROP_OBJ                                   ~1, 'link'
          6      > JMPZ                                                     ~2, ->9
          7    >   QM_ASSIGN                                        ~3      'No'
          8      > JMP                                                      ->10
          9    >   QM_ASSIGN                                        ~3      'Yes'
         10    >   SEND_VAL                                                 ~3
   95    11        DO_ICALL                                                 
   99    12      > RETURN                                                   null

End of function test_unset

Function dump_to_array:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 28, Position 2 = 30
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 33
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 37, Position 2 = 41
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 44, Position 2 = 48
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 48
Branch analysis from position: 41
Branch analysis from position: 30
filename:       /in/6F0nJ
function name:  dump_to_array
number of ops:  49
compiled vars:  !0 = $via_to_array, !1 = $via_to_array_props, !2 = $via_typecast, !3 = $via_typecast_props, !4 = $diff1, !5 = $diff2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  102     0  E >   FETCH_OBJ_R                                      ~6      'term'
          1        INIT_METHOD_CALL                                         ~6, 'to_array'
          2        DO_FCALL                                      0  $7      
          3        ASSIGN                                                   !0, $7
  103     4        INIT_FCALL                                               'array_keys'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $9      
          7        ASSIGN                                                   !1, $9
  104     8        FETCH_OBJ_R                                      ~11     'term'
          9        CAST                                          7  ~12     ~11
         10        ASSIGN                                                   !2, ~12
  105    11        INIT_FCALL                                               'array_keys'
         12        SEND_VAR                                                 !2
         13        DO_ICALL                                         $14     
         14        ASSIGN                                                   !3, $14
  107    15        INIT_FCALL                                               'array_diff'
         16        SEND_VAR                                                 !1
         17        SEND_VAR                                                 !3
         18        DO_ICALL                                         $16     
         19        ASSIGN                                                   !4, $16
  108    20        INIT_FCALL                                               'array_diff'
         21        SEND_VAR                                                 !3
         22        SEND_VAR                                                 !1
         23        DO_ICALL                                         $18     
         24        ASSIGN                                                   !5, $18
  110    25        ECHO                                                     '%0A%0AAre+the+results+the+same+between+WP_Term%3A%3Ato_array%28%29+and%28array%29+%24term%3F%0A'
  111    26        ISSET_ISEMPTY_CV                                 ~20     !4
         27      > JMPZ_EX                                          ~20     ~20, ->30
         28    >   ISSET_ISEMPTY_CV                                 ~21     !5
         29        BOOL                                             ~20     ~21
         30    > > JMPZ                                                     ~20, ->33
  112    31    >   ECHO                                                     'Yes%0A'
  111    32      > JMP                                                      ->48
  114    33    >   ECHO                                                     'No%0A'
  116    34        ISSET_ISEMPTY_CV                                 ~22     !4
         35        BOOL_NOT                                         ~23     ~22
         36      > JMPZ                                                     ~23, ->41
  117    37    >   ECHO                                                     '%0AWP_Term%3A%3Ato_array%28%29+vs+%28array%29+%24term%0A'
  118    38        INIT_FCALL                                               'var_dump'
         39        SEND_VAR                                                 !4
         40        DO_ICALL                                                 
  120    41    >   ISSET_ISEMPTY_CV                                 ~25     !5
         42        BOOL_NOT                                         ~26     ~25
         43      > JMPZ                                                     ~26, ->48
  121    44    >   ECHO                                                     '%0A%28array%29+%24term+vs+WP_Term%3A%3Ato_array%28%29%0A'
  122    45        INIT_FCALL                                               'var_dump'
         46        SEND_VAR                                                 !5
         47        DO_ICALL                                                 
  125    48    > > RETURN                                                   null

End of function dump_to_array

End of class Tester.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.9 ms | 1487 KiB | 19 Q