Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Public functions vs Functions in CodeIgniter

Tags:

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?

like image 226
Derfder Avatar asked Mar 24 '12 07:03

Derfder


1 Answers

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.

like image 102
Joseph Avatar answered Sep 28 '22 23:09

Joseph