lenerd3000 Posted May 2, 2008 Share Posted May 2, 2008 is there's a way how can i access parent class member in another class? class test { function t();{} } class test2 extends test { function t2();{} } class test3 extends test { function t3(); { // can i access t2 from here which is also a member of test class? } } Quote Link to comment Share on other sites More sharing options...
trq Posted May 3, 2008 Share Posted May 3, 2008 can i access t2 from here which is also a member of test class? No, test2 is in no way related to test3. Quote Link to comment Share on other sites More sharing options...
aschk Posted May 6, 2008 Share Posted May 6, 2008 you can only access it if t3 extends from t2. e.g. class t3 extends t2 { function t3(){ $this->t2(); } } What concerns me however is that you appear to be using php4 syntax. Convert to 5 before it's too late, otherwise you'll get left in the dark php ages... Quote Link to comment Share on other sites More sharing options...
lenerd3000 Posted May 6, 2008 Author Share Posted May 6, 2008 What concerns me however is that you appear to be using php4 syntax. Convert to 5 before it's too late, otherwise you'll get left in the dark php ages... really? i thought my syntax is already 5.. sori if it is... Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted May 6, 2008 Share Posted May 6, 2008 It is PHP 5 syntax. I think aschk is referring to that you are not explicitly declaring the methods as public. However, if you omit a visibility declaration for a method, then it will always be public implicitly. It's standard practice to always include it though. Quote Link to comment Share on other sites More sharing options...
aschk Posted May 13, 2008 Share Posted May 13, 2008 I think my sight was funny that day. For some reason or another I thought you were using the old fashioned constructor methods (i.e. for class test, you have a method called test). However, i realise you're not ... my bad. Anywho, the method (t2) that you were interested in using from test3 is a sibling method, and not a parent method. You can't utilise sibling methods as this breaks the fundamental rule of inheritance 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.