lenerd3000 Posted April 29, 2008 Share Posted April 29, 2008 hello, i have 2 classes on different page and will inherit a class from a 3rd page. now, i have my index page with a class inherited the class on the 3rd page. when i try to get function from the parent its ok but my problem is when i try to access the functions from the first 2 classes... how can i call the class that is a member of my parent?? test1.php class test1 extends test { function t1() { echo "test1"; } } test2.php class test1 extends test { function t2() { echo "test2"; } } test.php class test { function t() { echo "test"; } } index.php class access extends test { } $test = new test(); $test->t; // OK $test->t1; // ERROR $test->t2; // ERROR Quote Link to comment https://forums.phpfreaks.com/topic/103465-class-problem/ Share on other sites More sharing options...
rhodesa Posted April 29, 2008 Share Posted April 29, 2008 class TEST1 extends TEST...that means there is a new class TEST1, that uses TEST as a base and allows you to add stuff to it. this does not alter the methods/variables inside TEST Quote Link to comment https://forums.phpfreaks.com/topic/103465-class-problem/#findComment-529821 Share on other sites More sharing options...
lenerd3000 Posted April 29, 2008 Author Share Posted April 29, 2008 how can I access the other class with using the class in the index. i want to get all the class in one class so i can use them all but since classes in php could not make multiple extends Quote Link to comment https://forums.phpfreaks.com/topic/103465-class-problem/#findComment-529833 Share on other sites More sharing options...
rhodesa Posted April 29, 2008 Share Posted April 29, 2008 I would make it so the classes keep building on eachother... <?php class test { function t() { echo "test"; } } ?> <?php class test1 extends test { function t1() { echo "test1"; } } ?> <?php class test2 extends test1 { function t2() { echo "test2"; } } ?> <?php class access extends test2 { } $test = new access(); $test->t(); $test->t1(); $test->t2(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/103465-class-problem/#findComment-529857 Share on other sites More sharing options...
lenerd3000 Posted April 29, 2008 Author Share Posted April 29, 2008 is there's no other solution? i have done that but i need more flexible code. Quote Link to comment https://forums.phpfreaks.com/topic/103465-class-problem/#findComment-529873 Share on other sites More sharing options...
rhodesa Posted April 29, 2008 Share Posted April 29, 2008 I guess I don't understand what you are trying to do. Are you trying to declare a class, then programatically add methods to it? That is not possible. Can you try to explain what you are looking to specifically accomplish instead of speaking generically? Quote Link to comment https://forums.phpfreaks.com/topic/103465-class-problem/#findComment-529912 Share on other sites More sharing options...
lenerd3000 Posted April 29, 2008 Author Share Posted April 29, 2008 its too simple logic but hard for me to do. i want to use a class that calls all the classes i write base on what i need in one call. i have test1, test2, test3 classes separately and i will make a test4 class which if call, test1-test3 class will be inherited. do you know cakephp? i want to make framework and i base in on cake i dont know how did they integrate all the class and function in cake but when i try to trace it up, all of them inherits a class named Object. and all of the built-in classes can be call using $this-> but i cant figure out where did they made a connection for all the class. Quote Link to comment https://forums.phpfreaks.com/topic/103465-class-problem/#findComment-529915 Share on other sites More sharing options...
rhodesa Posted April 29, 2008 Share Posted April 29, 2008 Sorry, but I still don't follow. All I can say is the extend keyword, is like cloning the base class, so you can then add other stuff to it. Quote Link to comment https://forums.phpfreaks.com/topic/103465-class-problem/#findComment-529925 Share on other sites More sharing options...
phorman Posted April 30, 2008 Share Posted April 30, 2008 you must include the class on all pages that have inheritance. While php will allow you to pass the values of the object, the functions are not passed and you have to include them. ie: require_once("test.php"); class test1 extends test { function t1(){ echo "OK"; } } class test2 extends test1 { function t2() { echo "OK"; } } $new_object = @new test2; $new_object->t(); // OK $new_object->t1(); // OK $new_object->t2(); // OK Notice that the call to the class is the last extended class in the structure. If you call the first class, there's no way to access the other functions in the other extended classes. Quote Link to comment https://forums.phpfreaks.com/topic/103465-class-problem/#findComment-529949 Share on other sites More sharing options...
lenerd3000 Posted April 30, 2008 Author Share Posted April 30, 2008 ok thank you for your time in helping me. maybe it is not possible what is am thinking. Quote Link to comment https://forums.phpfreaks.com/topic/103465-class-problem/#findComment-530226 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.