php classes

[php]

<?php class myClass { public $hello = 'hello'; function printHello(){ echo $this->$hello; } } $obj = new myClass(); echo $obj->printHello(); ?>

[/php]

I am receiving this error
Fatal error: Cannot access empty property in /home/techbiz/public_html/187/class.php on line 8

Anyone know what I’m doing wrong?

Change this line:
[php] echo $this->$hello[/php]

to this:
[php] echo $this->hello[/php]

(remove the $ when dealing with variables in a class)

Thanks Smokey i did figure this out but that was it.

Sponsor our Newsletter | Privacy Policy | Terms of Service