0

I do not know if this is a good question. But which function, protected or private is more secure? Secure, I mean, access to external functions. Secure, I mean when I hack the code to get variables, using which will be harder to do??

pacanosiu
  • 37
  • 11

3 Answers3

3

Actualy these are not about security in the way you mean. It depends on which type of application your are trying to develop. All three types are secure if they are used in the right way.

If you are going to use the functions everywhere in the program you should use public. If you want to use them only when they are needed by the classes that extends that class you have to use protected. If you want to use it only inside that class you should use private.

Peshraw H. Ahmed
  • 439
  • 3
  • 22
2

This largely depends on context. Security to what? External access? Visibility modifiers are not going to stop data leaking outside of your application and you should know all the code that is live in your production environment.

I would be more focused on the likes of:

  • buffer overflows
  • SQL injection (e.g. use mysqli prepared statements and not mysql)
  • source code availability
  • cross-site request forgery
  • session hijacking.
ABC Taylor
  • 70
  • 8
2

Private : Access is possible only from inside the class (other methods).
Protected : Access is possible only for inheriting classes.
Public : Access is possible from any object

Reda Meskali
  • 275
  • 3
  • 9