Hi,
I am making a simple PHP framework, this has a 'base' class, then includes other classes, like a database abstraction class and a form validation class.
I have got the classes all working and including, but I cant seam to reference another sub class from with in a sub class?
example:
PHP Code:
<?php
require_once('db.php'); // databse class
require_once('validation.php'); // validation class
class Base {
function Base() {
// load extending classes
$this->db = new Db();
$this->validation = new Validation();
}
function test() {
print_r($this->validation->run());
}
}
class Db extends base {
function Db() {
}
function query($sql) {
//
}
}
class Validation extends base {
function Validation() {
}
function run() {
$this->db->query("SELECT * FROM `table`");
}
}
What I want to be able to do, is call a sub function from another sub function.
for example:
PHP Code:
<?php
// load main class, and my two sub classes
$instance = new Base();
// fire a function which has access to my validation class, and my DB class.
$instance->test();
however I get the PHP Error
Fatal error: Call to a member function query() on a non-object
I have tried using the parent:: tag at the top of my subclasses like below, but that didn't seam to help;
PHP Code:
class Db extends base {
function Db() {
parent::System();
}
Bookmarks