Sorry if this has already been answered, I am new to OOP in PHP. I'm trying to build an mvc for educational and testing purposes and to increase my knowledge of it. I'm stuck at one point, and can't figure it out. I'm sure it's a simple solution, but I don't know what the correct term/word would be to look it up.
If an answer already exists, please let me know.
Here is what I am trying to do:
class Load {
public function __construct(){
}
public function model($file_name){
include($file_name.'.php');
}
}
class Home_model extends M_F_Model{
function __construct() {
parent::__construct();
}
public static function test_this_model($var){
$result = $var.'+2';
return $result;
}
}
class M_F_Controller {
public $load;
public function __construct(){
$this->load = new Load();
}
}
class Home extends M_F_Controller{
function __construct(){
parent::__construct();
$this->load->model('home_model');
}
function index($var){
$result = Home_model::test_this_model($var);
return $result;
}
}
I would like to turn Home_model::test_this_model();
into $this->home_model->test_this_model();
without having to declare the instance of home_model
in the Home
class for each class I may want to include in the future, and to avoid using static functions.
Thanks in advance, let me know if you need any further information.