Jump to content

how to use an instance of a class inside another classs


lordzardeck

Recommended Posts

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'>&#8250; 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.

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);

  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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.