Custom global variable not working in function

I try to use this code and for the if statments I had to put a global $query_obj before the code, I do not know if is the case.

global $query_obj;
if ( is_a($query_obj, 'WP_Term') ) {
    $my_base_url = get_term_link($query_obj);
} elseif ( is_a($query_obj, 'WP_Post') ) {
    $my_base_url = get_permalink();
} else {
    $my_base_url = null;
}

this seems to be working properly this way. In my wordpress only returns null. but the global variable $my_base_url is working fine when whe call $global $query_obj before the if’s statments.

global $query_obj;
if ( is_a($query_obj, 'WP_Term') ) {
    $my_base_url = get_term_link($query_obj);
} elseif ( is_a($query_obj, 'WP_Post') ) {
    $my_base_url = get_permalink();
} else {
    $my_base_url="its null";
}
function ti(){
  global $my_base_url;
  echo '<pre>';
  print_r($my_base_url);
  echo '</pre>';
}
ti();

Now to test the function I will need the $args , $items variables at least..

If you have the wp_debug set to true in wp_config.php this error should appear

define( 'WP_DEBUG', true );

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)