'Using underscore before public function names
I was just reading some code and I came across a function named __toString
. Here is the function prototype:
public function __construct($par)
What is the reason the coder chose __construct and not construct as the function name?
I have read this question which says that private and protected functions can start with an underscore, but it is a public function. Why has the coder chosen to use underscore in this case?
Solution 1:[1]
__construct and __toString are all magic functions that start with a double _.
And all private functions start with a single _ that is not standard, but developers prefer this way to identify public and private methods...
And all magic function are not public.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Peter Mortensen |