Magento Observer函数与外部PHP类错误

I am trying to accomplish something which I think is getting beyond my current PHP skills! I have working code in a Magento .phtml template file that calls an external PHP class e.g.

$ExternalLibPath=Mage::getModuleDir('', 'My_Module') . DS . 'lib' . DS .'class.authentication.php';
require_once ($ExternalLibPath);
$myauth = new Authentication();
$credentials = $myauth->get("account_credentials");
echo "Connecting as " . $credentials->user_name ;

(In the .phtml file the classes are called from an include). I'm trying to move the code from the frontend template files to a Magento module/extension with a class triggered on an event. My module works fine up until the external classes are accessed where trying to access *$credentials->user_name* causes an Undefined property: stdClass: error.

I don't understand why the code works in a .phtml template and not in the module, or what I am doing wrong!

Any help would be appreciated.

Pete.

You should call the class directly from the phtml:

$credentials = Mage::getModel('namespace/custom_class')->getAccountCredentials();

and return whatever you need to.