3v4l.org

run code in 300+ PHP versions simultaneously
<?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() );

preferences:
24.13 ms | 405 KiB | 5 Q