steelmanronald06 Posted July 14, 2007 Share Posted July 14, 2007 Okay, I have two classes set up. Both classes have functions. For example, we will call them class1 and class2. so i have class1 and class2 called like so: $class1 = new class1; $class2 = new class2; now then, can class2 reach into class one and grab a function? and if so, how do I accomplish that? do i have to do: class class2 { function tester() { class1func(); } or do i have to do: class class2 { function tester() { global $class1 $class1->class1func(); } ??? the reason i ask is i created a mysql class that has my most used mysql functions simplified for me, and I want to use my mysql query function from the mysql class in my news class to draw the news from the database. Quote Link to comment Share on other sites More sharing options...
keeB Posted July 14, 2007 Share Posted July 14, 2007 2 ways. 1. Object A uses instance of Object B <?php class a { function a () { $this->b = new b; } function get() { return $this->b->val; } } ?> 2. Object B extends Object A <?php class a { public $val = "hio"; function a() { $this->val = "hello"; } } class b extends a { function b() { a::a(); print $this->val; } } Quote Link to comment Share on other sites More sharing options...
trq Posted July 14, 2007 Share Posted July 14, 2007 That second example should be... <?php class a { public $val = "hio"; function a() { $this->val = "hello"; } } class b extends a { function b() { $this->a(); print $this->val; } } ?> Quote Link to comment Share on other sites More sharing options...
keeB Posted July 14, 2007 Share Posted July 14, 2007 Thanks for that.. my bad for typing the example in the box 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.