Welcome Guest, Not a member yet? Register   Sign In
Difference between private keyword and underscore before function name
#1

[eluser]John5788[/eluser]
Hello,

I am reading a tutorial for CI and I noticed the author uses the keywords public private such as

Code:
<?php
class Login extends Controller {

    public function __construct() {
        parent::Controller();

        $this->load->helper(array('form','url'));
        $this->load->library('form_validation');
    }

    public function index() {
        $this->load->view('login_form');
    }

    public function submit() {

        if ($this->_submit_validate() === FALSE) {
            $this->index();
            return;
        }

        redirect('/');

    }

    private function _submit_validate() {

    }

}

The user guide here: http://ellislab.com/codeigniter/user-gui...llers.html only says that an underscore before the function name is sufficient to be declared as a private function.

Is this just redundancy or is there a difference between the two methods?
#2

[eluser]danmontgomery[/eluser]
The public and private keywords were not supported until PHP5. Before then, it was generally accepted that adding an underscore to the beginning of a method name was declaring it "private". In this way, controller functions that start with _ are not accessible through a URL.




Theme © iAndrew 2016 - Forum software by © MyBB