- var_dump: documentation ( source)
- get_object_vars: documentation ( source)
<?php
#[AllowDynamicProperties]
class WP_Term {
public $term_id;
/**
* Converts an object to array.
*
* @since 4.4.0
*
* @return array Object as array.
*/
public function to_array() {
return get_object_vars( $this );
}
}
$term = new WP_Term();
$term->term_id = 5;
$term->foo = 'foo';
$term->bar = 'bar';
echo "Direct type cast to `(array)`\n";
var_dump( (array) $term );
echo "\n\nUsing to_array()\n";
var_dump( $term->to_array() );