user379888
user379888

Reputation:

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?

Upvotes: 0

Views: 644

Answers (1)

sandeep
sandeep

Reputation: 2234

__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.

Upvotes: 2

Related Questions