What is the difference between public, private, and protected?

When and why should I use public, private, and protected functions and variables inside a class? What is the difference between them? Examples: // Public public $variable; public function doSomething() { // … } // Private private $variable; private function doSomething() { // … } // Protected protected $variable; protected function doSomething() { // … … Read more

simple solution for restricting access to (some) uploads/downloads

Initial Situation For a site I’m setting up I was looking into the whole field of securing uploads/downloads and restricting access to them based on user roles/capabilities. Of course I have read some of the previous questions related to the (general) topic on here, for reference reasons the most important/interesting ones I found: How to … Read more

What is the difference between public, protected, package-private and private in Java?

In Java, are there clear rules on when to use each of access modifiers, namely the default (package private), public, protected and private, while making class and interface and dealing with inheritance? 30 30 The official tutorial may be of some use to you. Class Package Subclass(same pkg) Subclass(diff pkg) World public + + + … Read more

What is the use of a private static variable in Java?

Of course it can be accessed as ClassName.var_name, but only from inside the class in which it is defined – that’s because it is defined as private. public static or private static variables are often used for constants. For example, many people don’t like to “hard-code” constants in their code; they like to make a public static or private static variable with a meaningful … Read more