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? Quote Link to comment 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] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.