Fatal error: Call to a member function menu_order() on a non-object

hmm, why is an error sparked here?

Fine:

var_dump($men->menu_order());

Not fine:


function user_menu() {
    
    var_dump($men->menu_order());

}

user_menu();

The variable $men is not part of the scope for your user_menu() function, simply add a global with $men in it and the error should go away.

function user_menu() {
    global $men;
    
    var_dump($men->menu_order());
}

user_menu();

or pass $men in as a parameter.

function user_menu($men) {

user_menu($men);

You should avoid from using “global” at all cost.