N-Bomb(Nerd) Posted June 17, 2009 Share Posted June 17, 2009 So, I'm pretty new to using classes and I've made my script. However, I just got to the part of showing the output on the website and I don't know how to access the variables within the class. How would one do this? Like for example, within my class this would be a variable: $this->Username How exactly do I access the contents of that variable outside of the class? Quote Link to comment https://forums.phpfreaks.com/topic/162538-solved-classes-grabbing-variables/ Share on other sites More sharing options...
Yesideez Posted June 17, 2009 Share Posted June 17, 2009 First you have to make an instance of your class like this $instance=new myclass(); Then, to access the variables use it like this: echo $instance->Username; Quote Link to comment https://forums.phpfreaks.com/topic/162538-solved-classes-grabbing-variables/#findComment-857836 Share on other sites More sharing options...
KevinM1 Posted June 17, 2009 Share Posted June 17, 2009 It should be noted that directly accessing object properties is a Bad Idea. You should implement accessor functions instead. Quote Link to comment https://forums.phpfreaks.com/topic/162538-solved-classes-grabbing-variables/#findComment-857979 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.