In PHP, What is the difference between declaring methods inside class like
public function
VS function
For example:
public function contact() { $data['header'] = "Contact"; $this->load->view('admin/admin_contact', $data); }
VS
function contact() { $data['header'] = "Contact"; $this->load->view('admin/admin_contact', $data); }
Is it better practice to use public function or function and why?
According to PHP.net
Class methods may be defined as public, private, or protected. Methods declared without any explicit visibility keyword are defined as public.
for best practice, i suggest using visibility keywords (esp when using higher versions of PHP). it prevents confusion (like the one you are in now) and promotes standard practice in coding.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With