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? 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; 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. Link to comment https://forums.phpfreaks.com/topic/162538-solved-classes-grabbing-variables/#findComment-857979 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.