To use the variable passed in constructor throughout your class, you can create a class level variable like this:
class User {
private $tokenID = NULL;
function __construct($tokenID){
// store token id in class level variable
$this->tokenID = $tokenID;
}
function someFun($authtoken) {
echo $this->tokenID;
}
}
You need to create the constructor in order to do that:
class User {
function __construct($tokenID){
// do something with $tokenID
}
function getFbId($authtoken) {
// code
}
function getFbFirstName ($authtoken) {
// code
}
}
Note:
If you are using PHP4, a constructor can be created with a function name same as that of class like:
class User {
function User($tokenID){
// do something with $tokenID
}
function getFbId($authtoken) {
// code
}
function getFbFirstName ($authtoken) {
// code
}
}
Now you can do something like:
$user = new User($authtoken);