tags:

views:

87

answers:

3

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

What is the default visibility in PHP for functions without a visibility declaration. Does PHP have a package visibility like in Java? Example:

class test {
  -- is go public or private?
  function go() {

  }
}

The reason I asked because I've seen many contructors code written:

function __contruct() and some public function __constuct(). Are they equivalent?

+2  A: 

Default is public. It's a good practice to allways include it, however, PHP 4 supported classes without access modifiers, so it's common to see no usage of them on legacy code.

And no, PHP has no package visibility, mainly because until recently PHP had no packages.

Johnco
+1  A: 

The default is public. The reason probably is backwards compatibility as old code expects it to be public (it would stop working if it weren't public).

Tomas Markauskas
+6  A: 

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

Jansen Price