View Single Post
Old 10-21-2009, 07:39 PM   #1 (permalink)
Etheco
The Visitor
 
Etheco's Avatar
 
Join Date: Oct 2009
Posts: 4
Thanks: 0
Etheco is on a distinguished road
Help Classes (Explained inside)

Hi There as you can tell i am new to the community so firstly.

Hey all :D

Right to go into my problem. This is to write my own class base and core system. Read the code below to understand me further.

So all classes below will be seperate files. and will be included seperatly.

PHP Code:
class Base {
   public function 
load_class($class_name) { 
      include(
'core/'.$class_name.'.class.php');
      
$this->$class_name = new $class_name();
      }
}

class 
Logging {
   public function 
error($msg) {
      
print_r($msg);
      }

}

class 
Database extends Base {
   public function 
connect($coninfo) {
      
$this->Logging->error($coninfo);
      }

}

include(
'core/Base.class.php');
$Base = new Base();

$Base->load_class('Logging');
$Base->load_class('Database');
$Base->Database->connect('info'); 
Ok it all works up untill i run the connect, when i try to use $this->Logging->error(); it produces a error

Fatal error: Call to a member function error() on a non-object

Hope i explained it ok :(. Basicly i need to be able to use the classes i setup in the Base obj.

Thank you so so much in advanced :D
Etheco is offline  
Reply With Quote