I'm brand spanking new to objects/classes and starting from the ground up (after using procedural code for a good few years). I'm just testing out basic input/output using an IF statement to get used to it all... <?php //This would be stored in a class file class Testclass { public $testvarb = "Signed In"; public $testvar = "Not signed in"; function dosomething() { echo $this->testvar; } function dosomethingb() { echo $this->testvarb; } } //This would be called out on the page //Check if user is logged in $Testclass = new Testclass(); $loggedin = "0"; if ($loggedin == "1") { $Testclass->dosomething(); } else { $Testclass->dosomethingb(); } ?> PHP: Its outputting backwards... 0 outputs "Signed In" whereas 1 outputs "Not Signed In" Please don't fix the code, just advise me what is wrong. Thanks.
$loggedin = "0"; if ($loggedin == "1") { $Testclass->dosomething(); // Not used } else { $Testclass->dosomethingb(); // calls testvarb = "Signed In"; } Here is the other way $loggedin = "1"; if ($loggedin == "1") { $Testclass->dosomething(); // $testvar = "Not signed in"; } else { $Testclass->dosomethingb(); // Not used } So you need to change this line ($loggedin == "1") to ($loggedin == "0")
class properties is encapsulated, you need getter/setter (ask google for this) and class property which hold current login state. also, use boolean comparison, a complete fix here: http://pastie.org/5038325 not directly added by your request
I think you were thinking backwards when you named the two variables at the top of the class. You have $testvarb first but "Signed In" first. Didn't you mean $testvar = "Signed In" and $testvarb = "Not Signed In"?