title: php return global variable
body: <p>I have variable which may be set and contain some string, if not I need to find this string another way. I decided to use ternary operator with anonymous functions, first function is used when value of variable is set, second when not.</p>
  
  <p>The problem is, the first function doesn't return any value, why not?</p>
  
  <pre><code>// This line is just for testing purposes so the first anonymous function is run
  $variable = "value test";
  
  $variable = isset($variable) ?
  function() { global $variable; return $variable; } :
  function() {
    $tmp = JFactory::GetDocument()-&gt;base;
    $tmp = explode('/', JFactory::GetDocument()-&gt;base);
    $tmp = explode('-', $tmp[count($tmp)-1]);
    unset($tmp[0]);
  
    return implode(' ', $tmp);  
  };
  
  print_r($variable);
  </code></pre>