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'; /** * Declare each of the known, named dynamic properties. */ 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->dump_to_array(); $this->test_unset(); } 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"; printf( "\n\nAdditional props: %s\n", implode(', ', $this->get_additional_props_from_object_as_array( $via_to_array_props ) ) ); } 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); } printf( "\n\nAdditional props via WP_Term::to_array(): %s\n", implode(', ', $this->get_additional_props_from_object_as_array( $via_to_array_props ) ) ); printf( "\n\nAdditional props via (array) \$terms: %s\n", implode(', ', $this->get_additional_props_from_object_as_array( $via_typecast_props ) ) ); } } private function get_additional_props_from_object_as_array($object_as_array) { $base_declared_props = array('term_id', 'name', 'slug', 'term_group', 'term_taxonomy_id','taxonomy', 'description', 'parent', 'count', 'filter'); $additional_props = array(); foreach ($object_as_array as $prop) { if ( in_array( $prop, $base_declared_props, true)) { continue; } $additional_props[] = $prop; } return $additional_props; } } (new Tester( new WP_Term() ) )->test();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SpW2N
function name:  (null)
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  153     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/SpW2N
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/SpW2N
function name:  to_array
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   INIT_FCALL                                               'get_object_vars'
          1        FETCH_THIS                                       ~0      
          2        SEND_VAL                                                 ~0
          3        DO_ICALL                                         $1      
          4      > RETURN                                                   $1
   38     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/SpW2N
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
-------------------------------------------------------------------------------------
   40     0  E >   RECV                                             !0      
   42     1        IS_EQUAL                                                 !0, 'data'
          2      > JMPNZ                                                    ~4, ->4
          3    > > JMP                                                      ->27
   43     4    >   NEW                                              $5      'stdClass'
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !1, $5
   45     7        ASSIGN                                                   !2, <array>
   46     8      > FE_RESET_R                                       $9      !2, ->19
          9    > > FE_FETCH_R                                               $9, !3, ->19
   47    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
   46    18      > JMP                                                      ->9
         19    >   FE_FREE                                                  $9
   51    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
   53    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/SpW2N
function name:  __construct
number of ops:  4
compiled vars:  !0 = $term
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   60     0  E >   RECV                                             !0      
   61     1        ASSIGN_OBJ                                               'term'
          2        OP_DATA                                                  !0
   62     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/SpW2N
function name:  test
number of ops:  15
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   65     0  E >   INIT_METHOD_CALL                                         'test_isset'
          1        SEND_VAL_EX                                              'before'
          2        DO_FCALL                                      0          
   67     3        INIT_METHOD_CALL                                         'test_get'
          4        DO_FCALL                                      0          
   68     5        INIT_METHOD_CALL                                         'test_set'
          6        DO_FCALL                                      0          
   70     7        INIT_METHOD_CALL                                         'test_isset'
          8        SEND_VAL_EX                                              'after'
          9        DO_FCALL                                      0          
   72    10        INIT_METHOD_CALL                                         'dump_to_array'
         11        DO_FCALL                                      0          
   74    12        INIT_METHOD_CALL                                         'test_unset'
         13        DO_FCALL                                      0          
   75    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/SpW2N
function name:  test_get
number of ops:  5
compiled vars:  !0 = $term_data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   78     0  E >   FETCH_OBJ_R                                      ~1      'term'
          1        FETCH_OBJ_R                                      ~2      ~1, 'data'
          2        CAST                                          7  ~3      ~2
          3        ASSIGN                                                   !0, ~3
   79     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/SpW2N
function name:  test_isset
number of ops:  22
compiled vars:  !0 = $message, !1 = $prop
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   81     0  E >   RECV                                             !0      
   82     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
   84     5        FETCH_OBJ_R                                      ~5      'dyanmic_properties'
          6      > FE_RESET_R                                       $6      ~5, ->20
          7    > > FE_FETCH_R                                               $6, !1, ->20
   85     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                                                 
   84    19      > JMP                                                      ->7
         20    >   FE_FREE                                                  $6
   87    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/SpW2N
function name:  test_set
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   90     0  E >   FETCH_OBJ_W                                      $0      'term'
          1        ASSIGN_OBJ                                               $0, 'unknown'
          2        OP_DATA                                                  'unknown+dynamic+property'
   91     3        FETCH_OBJ_W                                      $2      'term'
          4        ASSIGN_OBJ                                               $2, 'link'
          5        OP_DATA                                                  'https%3A%2F%2Fexample.com%2F'
   92     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/SpW2N
function name:  test_unset
number of ops:  13
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   95     0  E >   FETCH_OBJ_UNSET                                  $0      'term'
          1        UNSET_OBJ                                                $0, 'link'
   97     2        INIT_FCALL                                               'printf'
   98     3        SEND_VAL                                                 '%0ATesting+unset%28%29%3A+Did+WP_Term%3A%3A%24link+unset%3F+%0A%25s%0A'
   99     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
   97    11        DO_ICALL                                                 
  101    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 = 44
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 81
Branch analysis from position: 81
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
2 jumps found. (Code = 43) Position 1 = 48, Position 2 = 52
Branch analysis from position: 48
2 jumps found. (Code = 43) Position 1 = 55, Position 2 = 59
Branch analysis from position: 55
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 59
Branch analysis from position: 52
Branch analysis from position: 30
filename:       /in/SpW2N
function name:  dump_to_array
number of ops:  82
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
-------------------------------------------------------------------------------------
  104     0  E >   FETCH_OBJ_R                                      ~6      'term'
          1        INIT_METHOD_CALL                                         ~6, 'to_array'
          2        DO_FCALL                                      0  $7      
          3        ASSIGN                                                   !0, $7
  105     4        INIT_FCALL                                               'array_keys'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $9      
          7        ASSIGN                                                   !1, $9
  106     8        FETCH_OBJ_R                                      ~11     'term'
          9        CAST                                          7  ~12     ~11
         10        ASSIGN                                                   !2, ~12
  107    11        INIT_FCALL                                               'array_keys'
         12        SEND_VAR                                                 !2
         13        DO_ICALL                                         $14     
         14        ASSIGN                                                   !3, $14
  109    15        INIT_FCALL                                               'array_diff'
         16        SEND_VAR                                                 !1
         17        SEND_VAR                                                 !3
         18        DO_ICALL                                         $16     
         19        ASSIGN                                                   !4, $16
  110    20        INIT_FCALL                                               'array_diff'
         21        SEND_VAR                                                 !3
         22        SEND_VAR                                                 !1
         23        DO_ICALL                                         $18     
         24        ASSIGN                                                   !5, $18
  112    25        ECHO                                                     '%0A%0AAre+the+results+the+same+between+WP_Term%3A%3Ato_array%28%29+and%28array%29+%24term%3F%0A'
  113    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, ->44
  114    31    >   ECHO                                                     'Yes%0A'
  115    32        INIT_FCALL                                               'printf'
         33        SEND_VAL                                                 '%0A%0AAdditional+props%3A+%25s%0A'
         34        INIT_FCALL                                               'implode'
         35        SEND_VAL                                                 '%2C+'
         36        INIT_METHOD_CALL                                         'get_additional_props_from_object_as_array'
         37        SEND_VAR_EX                                              !1
         38        DO_FCALL                                      0  $22     
         39        SEND_VAR                                                 $22
         40        DO_ICALL                                         $23     
         41        SEND_VAR                                                 $23
         42        DO_ICALL                                                 
  113    43      > JMP                                                      ->81
  117    44    >   ECHO                                                     'No%0A'
  119    45        ISSET_ISEMPTY_CV                                 ~25     !4
         46        BOOL_NOT                                         ~26     ~25
         47      > JMPZ                                                     ~26, ->52
  120    48    >   ECHO                                                     '%0AWP_Term%3A%3Ato_array%28%29+vs+%28array%29+%24term%0A'
  121    49        INIT_FCALL                                               'var_dump'
         50        SEND_VAR                                                 !4
         51        DO_ICALL                                                 
  123    52    >   ISSET_ISEMPTY_CV                                 ~28     !5
         53        BOOL_NOT                                         ~29     ~28
         54      > JMPZ                                                     ~29, ->59
  124    55    >   ECHO                                                     '%0A%28array%29+%24term+vs+WP_Term%3A%3Ato_array%28%29%0A'
  125    56        INIT_FCALL                                               'var_dump'
         57        SEND_VAR                                                 !5
         58        DO_ICALL                                                 
  128    59    >   INIT_FCALL                                               'printf'
  129    60        SEND_VAL                                                 '%0A%0AAdditional+props+via+WP_Term%3A%3Ato_array%28%29%3A+%25s%0A'
  130    61        INIT_FCALL                                               'implode'
         62        SEND_VAL                                                 '%2C+'
         63        INIT_METHOD_CALL                                         'get_additional_props_from_object_as_array'
         64        SEND_VAR_EX                                              !1
         65        DO_FCALL                                      0  $31     
         66        SEND_VAR                                                 $31
         67        DO_ICALL                                         $32     
         68        SEND_VAR                                                 $32
  128    69        DO_ICALL                                                 
  133    70        INIT_FCALL                                               'printf'
  134    71        SEND_VAL                                                 '%0A%0AAdditional+props+via+%28array%29+%24terms%3A+%25s%0A'
  135    72        INIT_FCALL                                               'implode'
         73        SEND_VAL                                                 '%2C+'
         74        INIT_METHOD_CALL                                         'get_additional_props_from_object_as_array'
         75        SEND_VAR_EX                                              !3
         76        DO_FCALL                                      0  $34     
         77        SEND_VAR                                                 $34
         78        DO_ICALL                                         $35     
         79        SEND_VAR                                                 $35
  133    80        DO_ICALL                                                 
  138    81    > > RETURN                                                   null

End of function dump_to_array

Function get_additional_props_from_object_as_array:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 15
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 15
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 12
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/SpW2N
function name:  get_additional_props_from_object_as_array
number of ops:  18
compiled vars:  !0 = $object_as_array, !1 = $base_declared_props, !2 = $additional_props, !3 = $prop
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  140     0  E >   RECV                                             !0      
  141     1        ASSIGN                                                   !1, <array>
  142     2        ASSIGN                                                   !2, <array>
  143     3      > FE_RESET_R                                       $6      !0, ->15
          4    > > FE_FETCH_R                                               $6, !3, ->15
  144     5    >   INIT_FCALL                                               'in_array'
          6        SEND_VAR                                                 !3
          7        SEND_VAR                                                 !1
          8        SEND_VAL                                                 <true>
          9        DO_ICALL                                         $7      
         10      > JMPZ                                                     $7, ->12
  145    11    > > JMP                                                      ->4
  147    12    >   ASSIGN_DIM                                               !2
         13        OP_DATA                                                  !3
  143    14      > JMP                                                      ->4
         15    >   FE_FREE                                                  $6
  149    16      > RETURN                                                   !2
  150    17*     > RETURN                                                   null

End of function get_additional_props_from_object_as_array

End of class Tester.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.74 ms | 1493 KiB | 21 Q