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??
-
2Please define what you mean by 'secure'? – Nigel Ren May 09 '18 at 20:29
-
secure, I mean, access to external functions – pacanosiu May 09 '18 at 20:31
-
You mean whether or not "external functions" can access protected or private methods? Or what does it mean? – Felix Kling May 09 '18 at 20:33
-
I think you may be better looking up how variable scoping works in your language of choice. – GrumpyMonkey May 09 '18 at 20:34
-
1*"when I'm hacking code variables"* And what does that mean now? – Felix Kling May 09 '18 at 20:38
3 Answers
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.

- 439
- 3
- 22
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 notmysql
) - source code availability
- cross-site request forgery
- session hijacking.

- 70
- 8
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

- 275
- 3
- 9
-
1*"Access is possible only for inheriting classes."* and from other own class methods of course. – Felix Kling May 09 '18 at 20:37
-
1as far as i can recall, `friend` objects can access private methods/variables too – Ali Yılmaz May 09 '18 at 20:38
-