Demonic Posted September 3, 2006 Share Posted September 3, 2006 [code=php:0]<?phpclass MyClass { var $statement; function PrintToScreen(){ echo $statement; } } $class = new MyClass; $class->$statement = "hi"; $class->PrintToScreen();?>[/code]I tried doing this but it wont print hi any suggestions? Link to comment https://forums.phpfreaks.com/topic/19546-oop-problem/ Share on other sites More sharing options...
extrovertive Posted September 3, 2006 Share Posted September 3, 2006 If you want to do something with variables defined in your class, you must use a $this pointer to access it within the class.[code=php:0]class MyClass { var $statement; function PrintToScreen(){ echo $this->statement; } } $class = new MyClass; $class->statement = "hi"; $class->PrintToScreen();[/code] Link to comment https://forums.phpfreaks.com/topic/19546-oop-problem/#findComment-85053 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.