I have a feeling I'm overlooking something simple but I can't figure out how to get a value from a function that is called by the constructor within my class. The below is a very simple example but, essentially, I need to use the userId value on my index.php page which is returned by the function getUser which is called by the constructor.
Thank you in advance for the help!
index.php:
$test = new Test($username);
//Need to get value of userId here....
class/function:
class Test
{
//CONSTRUCTOR
public function __construct($username)
{
$this->getUserId($username);
}
//GET USER ID
public function getUserId($username)
{
//DB query here to get id
return $userId;
}
}
I should add that I know I can initialize the class then call the function from index.php and get the value that way. This is very simple example but some of the scripts I'm working on call 6 or 7 functions from within the constructor to perform various tasks.