I was wondering if you could overload functions in PHP, specifically in CodeIgniter. For instance in my Controller if I were to load a view, but it would differ whether a variable was supplied as a parameter or if it was left blank. This is the concept I tried, which is how I learned in other languages:
<?php
function load_view(){
$this->load->view('view');
}
function load_view($var){
$this->load->model('data');
$data = $this->data->getInfo($var);
$this->load->view('view', $data);
}
?>
But when I tried this, I get an error “Fatal error: Cannot redeclare Controller::load_view”…
Any help would be greatly appreciated.
Thanks in advance!
In PHP to overload functions use optional parameters. An example might be: