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? } } Link to comment https://forums.phpfreaks.com/topic/103912-access-class-member/ 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. Link to comment https://forums.phpfreaks.com/topic/103912-access-class-member/#findComment-532270 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... Link to comment https://forums.phpfreaks.com/topic/103912-access-class-member/#findComment-534232 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... Link to comment https://forums.phpfreaks.com/topic/103912-access-class-member/#findComment-534377 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. Link to comment https://forums.phpfreaks.com/topic/103912-access-class-member/#findComment-534549 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 Link to comment https://forums.phpfreaks.com/topic/103912-access-class-member/#findComment-539727 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.