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->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_to_array_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();

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.4.20.0140.00721.39
8.4.10.0100.00619.38
8.3.150.0100.01016.67
8.3.140.0090.00918.33
8.3.130.0000.00916.82
8.3.120.0090.00020.45
8.3.110.0090.00018.48
8.3.100.0430.00437.54
8.3.90.0360.01037.54
8.3.80.0400.01037.54
8.3.70.0420.00737.54
8.3.60.0360.01837.54
8.3.50.0440.00837.54
8.3.40.0550.00337.54
8.3.30.0320.01437.54
8.3.20.0480.00037.54
8.3.10.0380.01437.54
8.3.00.0320.00437.54
8.2.270.0040.00416.66
8.2.260.0110.01116.68
8.2.250.0040.00418.49
8.2.240.0160.00318.73
8.2.230.0000.00920.94
8.2.220.0170.00237.54
8.2.210.0220.01637.54
8.2.200.0230.00337.54
8.2.190.0260.00737.54
8.2.180.0090.00937.54
8.2.170.0170.00337.54
8.2.160.0200.00637.54
8.2.150.0330.00737.54
8.2.140.0380.00837.54
8.2.130.0390.00637.54
8.2.120.0350.00937.54
8.2.110.0300.01337.54
8.2.100.0360.00837.54
8.2.90.0290.00937.54
8.2.80.0370.00737.54
8.2.70.0430.00037.54
8.2.60.0290.01037.54
8.2.50.0360.00737.54
8.2.40.0370.00437.54
8.2.30.0350.00937.54
8.2.20.0360.00637.54
8.2.10.0330.00637.54
8.2.00.0250.00337.54
8.1.310.0190.00016.10
8.1.300.0060.00318.65
8.1.290.0360.00037.54
8.1.280.0190.00637.54
8.1.270.0220.01837.54
8.1.260.0320.01437.54
8.1.250.0390.01037.54
8.1.240.0180.00737.54
8.1.230.0140.00837.54
8.1.220.0250.00737.54
8.1.210.0290.00337.54
8.1.200.0290.00737.54
8.1.190.0240.01237.54
8.1.180.0260.01337.54
8.1.170.0330.00637.54
8.1.160.0210.01837.54
8.1.150.0360.00437.54
8.1.140.0290.00637.54
8.1.130.0260.01537.54
8.1.120.0360.00337.54
8.1.110.0460.01137.54
8.1.100.0220.00537.54
8.1.90.0150.00437.54
8.1.80.0180.00737.54
8.1.70.0160.01237.54
8.1.60.0280.01037.54
8.1.50.0210.00637.54
8.1.40.0120.00837.54
8.1.30.0160.00437.54
8.1.20.0360.00837.54
8.1.10.0460.00037.54
8.1.00.0330.01137.54

preferences:
25.88 ms | 403 KiB | 5 Q