Some thing that may be obvious to the seasoned PHP programmer, but may surprise someone coming over from C++:
<?php
class Foo
{
$bar = 'Hi There';
public function Print(){
echo $bar;
}
}
?>
Gives an error saying Print used undefined variable. One has to explicitly use (notice the use of<?php $this->bar ?>
):
<?php
class Foo
{
$bar = 'Hi There';
public function Print(){
echo this->$bar;
}
}
?>
<?php echo $this->bar; ?>
refers to the class member, while using $bar
means using an uninitialized variable in the local context of the member function.