Aureole Posted October 11, 2007 Share Posted October 11, 2007 I'm trying to learn a bit of OOP... Let's say I have this: <?php class message { var $hello; function defineMessage($something) { $this->hello = $something; } function showMessage() { echo $this->hello; } } $message = new message; $message->defineMessage('Hello World.'); $message->showMessage(); ?> Well that works fine but I've been trying to work out how to make it so I'll use $something->message->defineMsg(); and $something->message->showMsg(); I guess it's a Class in a Class... So I can have like... $swr3->db->connect(); ...rather than $swr3->connect(); or $db->connect(); Thanks a lot. Quote Link to comment Share on other sites More sharing options...
Aureole Posted October 11, 2007 Author Share Posted October 11, 2007 <?php class message { function definemsg($something) { $this->hello = $something; } function showmsg() { echo $this->hello; } } $swr3->message = new message; $swr3->message->definemsg('Hello World.'); $swr3->message->showmsg(); ?> This seems to work but the problem is, say if I have another class called bob I want $swr3 to still be used to get to the bob class... i.e. if I pretend I know what I'm doing for a second here's what I'd do... <?php class message { function defineMsg($something) { $this->hello = $something; } function showMsg() { echo $this->hello; } } class bob { function doStuff() { // Do stuff... } } $swr3->message = new message; $swr3->bob = new bob; $swr3->message->defineMsg('Hello World.'); $swr3->message->showMsg(); $swr3->bob->doStuff(); ?> EDIT: Lol that actually does work, yeay! Quote Link to comment Share on other sites More sharing options...
coder_ Posted October 11, 2007 Share Posted October 11, 2007 Read the manual!!!!!!!!! And read it now!!!! Quote Link to comment Share on other sites More sharing options...
Aureole Posted October 11, 2007 Author Share Posted October 11, 2007 I'd be 83 by the time I finished reading it. I do take a look at it sometimes but yeah... if everyone read the manual instead of posting this Forum would be dead. Quote Link to comment Share on other sites More sharing options...
coder_ Posted October 11, 2007 Share Posted October 11, 2007 I'd be 83 by the time I finished reading it. I do take a look at it sometimes but yeah... if everyone read the manual instead of posting this Forum would be dead. That is not true. 1. Learn basics. 2. If you have problem - google it. 3. can't find solution to your problem - post on forum. You should do first step. Quote Link to comment Share on other sites More sharing options...
Aureole Posted October 11, 2007 Author Share Posted October 11, 2007 I was joking hence the smilies, for your information I was looking at the manual and I did search Google. I always Google before posting here... well most of the time. 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.