Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
760 views
in Technique[技术] by (71.8m points)

oop - Default visibility of class methods in PHP

I looked at the manual, but I can't seem to find the answer.

What is the default visibility in PHP for methods without a visibility declaration? Does PHP have a package visibility like in Java?

For example, in the following code, is go() public or private?

class test {
  function go() {
  }
}

The reason I asked is that I've seen many constructors code written as function __construct() and some as public function __construct(). Are they equivalent?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Default is public.

Class methods may be defined as public, private, or protected. Methods declared without any explicit visibility keyword are defined as public.

http://www.php.net/manual/en/language.oop5.visibility.php


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...