PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I am using PHP5 and experimenting in using classes for the first time. My first attempt is pretty basic but yet kicking my butt. I define 2 classes. The first class defines a single variable. The second class has 3 functions. One function requires reading the variable from the first class. How do you do that? Here is an example of my code.
class member {
var $SignedIn;
function __construct()
{
// $this->SignedIn = 0; // test to indicate user is not signed in
$this->SignedIn = 1; // test to indicate user is signed in
}
}
class page {
{
function DisplayHeader()
{
// code goes here
}
function DisplayMenu()
{
// determines which links to display in the menu
if(member::SignedIn == 1) { echo "member signed in"; } else { echo "guest not signed in"; }
}
function DisplayFooter()
{
// code goes here
}
}
Glad I could help and sorry for missing your mistake!
If you're learning how to do classes I would recommend setting the variable that you passed into the function as a 'member variable' so you can store it for use later. That way if your page class needs to refer to the current member frequently you need not pass it as an argument every time.
All you need to add is the following to your page class, and create a mutator to set it initially.