lordzardeck Posted February 26, 2009 Share Posted February 26, 2009 for some reason, anytime I try to initiate an instance of another class inside a class, it stops working, without errors I might add, from then on. here is my code: require_once('./classes/interfaces/iplugin.php'); require_once('./classes/datahandler.php'); class catalog extends datahandler implements IPlugin{ //public $data; function get_menu(){ print "\n<a href='index.php?page=catalog' class='navigation'>› Catalog<br></a>"; ; } function get_content(){ //$this->data = new datahandler(); //$catalog = $this->data->search_results(); datahandler::_construct(); $catalog = datahandler::search_results(); print "<div style='height:375px; overflow: auto;'> <table width='732' cellspacing='0' class='stats'> <tr> <td class='hed' colspan='5'>Search Results:</td> </tr> <tr> <td width='99'><strong>Accession</strong></td> <td width='208'><strong>Title</strong></td> <td width='138'><strong>Publisher</strong></td> <td width='129'><strong>Subject </strong></td> <td width='146'><strong>Date Due </strong></td> </tr>"; echo $catalog; print "</table></div>"; } } If you need anything else, please let me know. Thanks for any help! **edit** Also, the commented code is so I could test different ways without having to type all over again. Quote Link to comment https://forums.phpfreaks.com/topic/147054-how-to-use-an-instance-of-a-class-inside-another-classs/ Share on other sites More sharing options...
rhodesa Posted February 26, 2009 Share Posted February 26, 2009 is search_results() a regular or static method of datahandler? regular: $this->data = new datahandler(); $catalog = $this->data->search_results(); static: $catalog = datahandler::search_results(); Quote Link to comment https://forums.phpfreaks.com/topic/147054-how-to-use-an-instance-of-a-class-inside-another-classs/#findComment-772058 Share on other sites More sharing options...
lordzardeck Posted February 26, 2009 Author Share Posted February 26, 2009 it's regular and i tried that. (I've tried using the code that's commented out) Quote Link to comment https://forums.phpfreaks.com/topic/147054-how-to-use-an-instance-of-a-class-inside-another-classs/#findComment-772066 Share on other sites More sharing options...
rhodesa Posted February 26, 2009 Share Posted February 26, 2009 for some reason, anytime I try to initiate an instance of another class inside a class, it stops working, without errors I might add, from then on. this leads me to believe you don't have error reporting enabled. at the very beginning of your script, put this following: ini_set ("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/147054-how-to-use-an-instance-of-a-class-inside-another-classs/#findComment-772093 Share on other sites More sharing options...
lordzardeck Posted February 26, 2009 Author Share Posted February 26, 2009 yep, i have that on too. It baffles me... Quote Link to comment https://forums.phpfreaks.com/topic/147054-how-to-use-an-instance-of-a-class-inside-another-classs/#findComment-772095 Share on other sites More sharing options...
Maq Posted February 26, 2009 Share Posted February 26, 2009 class catalog extends datahandler implements IPlugin extends datahandler{ Example straight from the manual - extends. error_reporting(E_ALL); class test { var $var; function test() { $this->var = 3; } } class testing extends test { function testing() { parent::test(); } function My_test() { return $this->var; } } $p = new testing(); echo $p->My_test(); // Returns 3 Quote Link to comment https://forums.phpfreaks.com/topic/147054-how-to-use-an-instance-of-a-class-inside-another-classs/#findComment-772099 Share on other sites More sharing options...
lordzardeck Posted February 26, 2009 Author Share Posted February 26, 2009 i'll try it Quote Link to comment https://forums.phpfreaks.com/topic/147054-how-to-use-an-instance-of-a-class-inside-another-classs/#findComment-772111 Share on other sites More sharing options...
Maq Posted February 26, 2009 Share Posted February 26, 2009 Should just be: $catalog = parent::search_results(); Quote Link to comment https://forums.phpfreaks.com/topic/147054-how-to-use-an-instance-of-a-class-inside-another-classs/#findComment-772117 Share on other sites More sharing options...
lordzardeck Posted February 27, 2009 Author Share Posted February 27, 2009 nope, didn't work. do you guys need the other code? Quote Link to comment https://forums.phpfreaks.com/topic/147054-how-to-use-an-instance-of-a-class-inside-another-classs/#findComment-772294 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.