I’m starting learning classes in PHP. I coded that:
class User {
function getFbId($authtoken) {
}
function getFbFirstName ($authtoken) {
}
}
What I want to do is something like that: $user=new User($authtoken); And pass the $authtoken to the class. It’s possible to define that when starting the class. It’s possible to retrieve that value inside a function of that class?
To use the variable passed in constructor throughout your class, you can create a class level variable like this:
You need to create the constructor in order to do that:
Note:
If you are using PHP4, a constructor can be created with a function name same as that of class like:
Now you can do something like: