Welcome Guest, Not a member yet? Register   Sign In
Underscore required for private functions?
#1

[eluser]Rolling[/eluser]
When using private functions in controllers, is it still necessary to prefix function names with an underscore?

Code:
//PHP 5+

private function something() {}


It seems that the private keyword is enough to 404 the function from public access, however is the underscore still necessary for any reason or is it just a CI styling convention?
#2

[eluser]CroNiX[/eluser]
I believe that is left over from when they were still trying to be backwards compatible with PHP4, but you're right, it isn't necessary with PHP5.

Personally I use them anyway as it makes it obvious when you're using it that its a private function/variable and makes the code easier to read that way.
#3

[eluser]Rolling[/eluser]
Thanks for that, I'm currently standardising my coding on my latest work. I've got a couple of earlier projects that I'm not quite ready to go back and do some house-cleaning on just yet. I'm used to writing in other languages so prefixing with private functions with underscores is a bit different.

For CI/PHP work I might do just that and use underscore prefixing for private functions and variables.
#4

[eluser]leela[/eluser]
For private functions we can use either underscore or private. Private supports in php5+. Underscore supports bellow versions also. That is the main difference.




Theme © iAndrew 2016 - Forum software by © MyBB