I want to call an external function in PHP from inside of a class function, but it does not work.
I've tried with include and require at various locations of the PHP class file, but without success.
The following function is located in the file Amd.php
<?php
function AmdGetFirstName($sUsername){
$oUserModel = new UserCoreModel;
$iProfileId = $oUserModel->getId(null, $sUsername);
$sFirstName = $oUserModel->getFirstName($iProfileId);
unset($oUserModel);
return $sFirstName;
}
Now I want to call this function from a class function with the following code:
<?php
require_once PATH_ROOT . '/Amd.php';
class Design
{
public function getProfileLink($sUsername)
{
$sFirstName = AmdGetFirstName($sUsername);
$sHtml = '<a href="';
$sHtml .= (new UserCore)->getProfileLink($sUsername);
$sHtml .= '" title="' . t("%0%'s profile", $sFirstName) . '">';
$sHtml .= $sFirstName . '</a>';
echo $sHtml;
}
}
When I debug the code the function AmdGetFirstName
is not called from within the public function getProfileLink
.
If I call the same function in the index.php file with the same require_once statement it works very well.
The difference what I can see is that in index.php the function is not called within another function or class function.
I also tried to locate the require_once statement inside of the class function with the same result.