3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php var_dump(get_catering_posts()); function get_catering_posts() { // For each category in the Catering category, fetch their posts return array_map(function ($category) { $category->posts = array_map(function (&$post) use ($category) { // Filter only the custom fields we need to render the page $post->custom_fields = array_filter(get_post_custom($post->ID), function ($item, $item_key) { return in_array($item_key, array( 'price', 'price_portion', 'serving', 'minimum_order', )); }, ARRAY_FILTER_USE_BOTH); return $post; }, get_posts(array( 'category' => $category->cat_ID, ))); return $category; }, get_categories(array( 'child_of' => 16, ))); } function get_posts($array) { return array( 0 => new stdClass, 1 => new stdClass, ); } function get_categories($array) { return array( 0 => new stdClass, 1 => new stdClass, ); } function get_post_custom($id) { return array( 'price' => 'price', 'price_portion' => 'price_portion', 'serving' => 'serving', 'minimum_order' => 'minimum_order', ); }
based on otWsI
Output for 5.6.8 - 7.3.1
Notice: Undefined property: stdClass::$cat_ID in /in/jp5f5 on line 15 Notice: Undefined property: stdClass::$ID in /in/jp5f5 on line 10 Notice: Undefined property: stdClass::$ID in /in/jp5f5 on line 10 Notice: Undefined property: stdClass::$cat_ID in /in/jp5f5 on line 15 Notice: Undefined property: stdClass::$ID in /in/jp5f5 on line 10 Notice: Undefined property: stdClass::$ID in /in/jp5f5 on line 10 array(2) { [0]=> object(stdClass)#2 (1) { ["posts"]=> array(2) { [0]=> object(stdClass)#5 (1) { ["custom_fields"]=> array(4) { ["price"]=> string(5) "price" ["price_portion"]=> string(13) "price_portion" ["serving"]=> string(7) "serving" ["minimum_order"]=> string(13) "minimum_order" } } [1]=> object(stdClass)#6 (1) { ["custom_fields"]=> array(4) { ["price"]=> string(5) "price" ["price_portion"]=> string(13) "price_portion" ["serving"]=> string(7) "serving" ["minimum_order"]=> string(13) "minimum_order" } } } } [1]=> object(stdClass)#3 (1) { ["posts"]=> array(2) { [0]=> object(stdClass)#7 (1) { ["custom_fields"]=> array(4) { ["price"]=> string(5) "price" ["price_portion"]=> string(13) "price_portion" ["serving"]=> string(7) "serving" ["minimum_order"]=> string(13) "minimum_order" } } [1]=> object(stdClass)#8 (1) { ["custom_fields"]=> array(4) { ["price"]=> string(5) "price" ["price_portion"]=> string(13) "price_portion" ["serving"]=> string(7) "serving" ["minimum_order"]=> string(13) "minimum_order" } } } } }
Output for 5.3.19 - 5.5.35
Notice: Undefined property: stdClass::$cat_ID in /in/jp5f5 on line 15 Notice: Undefined property: stdClass::$ID in /in/jp5f5 on line 10 Notice: Use of undefined constant ARRAY_FILTER_USE_BOTH - assumed 'ARRAY_FILTER_USE_BOTH' in /in/jp5f5 on line 12 Warning: array_filter() expects at most 2 parameters, 3 given in /in/jp5f5 on line 12 Notice: Undefined property: stdClass::$ID in /in/jp5f5 on line 10 Notice: Use of undefined constant ARRAY_FILTER_USE_BOTH - assumed 'ARRAY_FILTER_USE_BOTH' in /in/jp5f5 on line 12 Warning: array_filter() expects at most 2 parameters, 3 given in /in/jp5f5 on line 12 Notice: Undefined property: stdClass::$cat_ID in /in/jp5f5 on line 15 Notice: Undefined property: stdClass::$ID in /in/jp5f5 on line 10 Notice: Use of undefined constant ARRAY_FILTER_USE_BOTH - assumed 'ARRAY_FILTER_USE_BOTH' in /in/jp5f5 on line 12 Warning: array_filter() expects at most 2 parameters, 3 given in /in/jp5f5 on line 12 Notice: Undefined property: stdClass::$ID in /in/jp5f5 on line 10 Notice: Use of undefined constant ARRAY_FILTER_USE_BOTH - assumed 'ARRAY_FILTER_USE_BOTH' in /in/jp5f5 on line 12 Warning: array_filter() expects at most 2 parameters, 3 given in /in/jp5f5 on line 12 array(2) { [0]=> object(stdClass)#2 (1) { ["posts"]=> array(2) { [0]=> object(stdClass)#5 (1) { ["custom_fields"]=> NULL } [1]=> object(stdClass)#6 (1) { ["custom_fields"]=> NULL } } } [1]=> object(stdClass)#3 (1) { ["posts"]=> array(2) { [0]=> object(stdClass)#7 (1) { ["custom_fields"]=> NULL } [1]=> object(stdClass)#8 (1) { ["custom_fields"]=> NULL } } } }