How do I access database variables from a php function inside a block?

Permalink
I'm creating a custom block. Inside that blocks edit.php I'm using database variables defined in the blocks db.xml. To access them, I'm just writing $variable_name and it's all done since the C5 system takes care of the rest.

But here's something strange: I can access the database variables, as long as I'm NOT trying to access them from within a php function! Here's a code snippet:
<?php  
    defined('C5_EXECUTE') or die(_("Access Denied."));
   //This works
   echo $myvar;
   //This doesn't work
   echo myFunction();
   function myFunction()
   {
      return $myvar;
   }
?>


Can anyone tell me why this is?

 
guythomas replied on at Permalink Best Answer Reply
guythomas
The problem is due to variable scope. See here:
http://php.net/manual/en/language.variables.scope.php...