I've just started working with OOP in PHP. I'm creating an instance with a boolean value and running an if statement in a Class method. When running the true boolean value does not run the if statement. However when I run the same type of if statement outside of a class method it does work as expected. Why? Thanks for any clarifications, here's the code.
<?php
class Knowledge {
public $youKnow;
public function __construct($youKnow) {
$this->youKnow = $youKnow;
echo $youKnow; /* "1" */
echo "\n";
}
public function yesOr() {
if ($youKnow) {
echo "Now I know the basics of OOP!";
} else { echo "not"; }
/* "not" is echoed... */
}
}
$randInstance = new Knowledge(true);
$randInstance->yesOr();
$try = true;
if($try){
echo $try; /* "1" */
echo "this one works!"; /* "this one works! */
}
?>
Also how do I get the bool to return True (False) and not "1"?