0

I noticed that my senior wrote a few function names start with an underscore and some are normal. For example

funtion getData()
{
    return someData;
}

funtion _getData()
{
    return someData;
}

When I question that, He said _getData() function more secure to compare normal function. But I didn't understand. How it becomes more secure with an underscore. Is it true? if it is true. Can you explain more detailed example?

Note: I knew about __constructor(). It starts with double underscores.

Siddhu
  • 241
  • 2
  • 3
  • 16
  • 4
    *"But I didn't understand."* - Neither did he. If your colleague can't explain *why* it's "more secure" then your colleague is relying on spells and incantations instead of knowledge. Tread carefully when attempting to learn anything from this colleague. (Hint: It isn't "more secure". It has nothing to do with security. Never has.) – David Feb 25 '19 at 12:30
  • 1
    For the code and the interpreter there isn't any difference between `function getData()` and `function _getData()`. Starting the name with an underscore is an old code convention since the old days of PHP 4 that didn't support `protected` or `private` members. It is obsolete and not useful nowadays. – axiac Feb 25 '19 at 12:30

0 Answers0