I'm trying to brush up on some object oriented basics. I wrote this simple script but am confused as to why it works the way it does.
class Foo
{
function run($text = null)
{
$this->bar = strtolower($text);
echo $this->bar;
}
}
$foo = new Foo;
$foo->run('THIS IS SOME TEXT IN LOWER CASE');
The script outputs "this is some text in lower case" as expected.
But what i'm confused about is why I can do this without actually declaring the $bar variable. Why can I just use $this->bar? Maybe i'm not understanding how $this works properly, but I always thought you had to declare a variable prior to using it in the class. For example public $bar;
Thanks for any insights you may have.