Difference between functions and public functions in classes
class, function, php
Solution
Omitting the visibility is legacy code. PHP 4 did not support `public`, `protected` and `private`, all methods were `public`.
Short: `"public function" == "function" // true`
See also the PHP manual:
// This is public
function Foo()
{
$this->MyPublic();
$this->MyProtected();
$this->MyPrivate();
}
Similarly `var $attribute;` is equivalent to `public $attribute`. The `var` version also is PHP 4 legacy code.
Problem
In classes, most people use `public function name() { }` to define methods. However, I have seen several examples of them being defined without the `public` keyword, like `function name() { }`. I was confused by this because I thought you had to use public/private/protected when inside a class. I made the same sort of thing and `function` was doing the exact same job as `public function`. So my question is, what is the difference between using `function` and `public function` when inside a class?