Bloggers unite

"Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid." – Albert Einstein


PHP keywords which are used as access modifiers


@page { margin: 2cm }
th p { margin-bottom: 0cm; direction: ltr; color: #000000; orphans: 2; widows: 2 }
th p.western { font-family: “Liberation Serif”, “Times New Roman”, serif; font-size: 12pt; so-language: en-IN }
th p.cjk { font-family: “Noto Sans CJK SC”; font-size: 12pt; so-language: zh-CN }
th p.ctl { font-family: “Lohit Devanagari”; font-size: 12pt; so-language: hi-IN }
td p { margin-bottom: 0cm; direction: ltr; color: #000000; orphans: 2; widows: 2 }
td p.western { font-family: “Liberation Serif”, “Times New Roman”, serif; font-size: 12pt; so-language: en-IN }
td p.cjk { font-family: “Noto Sans CJK SC”; font-size: 12pt; so-language: zh-CN }
td p.ctl { font-family: “Lohit Devanagari”; font-size: 12pt; so-language: hi-IN }
h2 { direction: ltr; color: #000000; orphans: 2; widows: 2 }
h2.western { font-family: “Liberation Serif”, “Times New Roman”, serif; so-language: en-IN }
h2.cjk { font-family: “Noto Sans CJK SC”; so-language: zh-CN }
h2.ctl { font-family: “Lohit Devanagari”; so-language: hi-IN }
p { margin-bottom: 0.25cm; direction: ltr; color: #000000; line-height: 115%; orphans: 2; widows: 2 }
p.western { font-family: “Liberation Serif”, “Times New Roman”, serif; font-size: 12pt; so-language: en-IN }
p.cjk { font-family: “Noto Sans CJK SC”; font-size: 12pt; so-language: zh-CN }
p.ctl { font-family: “Lohit Devanagari”; font-size: 12pt; so-language: hi-IN }
code.cjk { font-family: “Courier New”, monospace }
a:link { so-language: zxx }

  1. public: When we define class members as public, then they are accessible from anywhere, even from outside of the class scope.

  2. private: When we define class members as private, they can only be accessed from within the class itself.

  3. protected: This is same as private, with one exception, the class members defined as protected can still be accessed from its subclass(We will learn about subclasses when we will learn about Inheritance).

  4. abstract: This keyword is only used for PHP classes and its member functions.

  5. final: The class methods defined as final, can not be changed or overriden by any subclass.

When to use Which Access Modifier: We cannot use all the available access modifers with class, its varibales and methods. In the table below, we have specified which access specifier is applied to what:

Access Modifer

classes

functions

variables

public

Not Applicable

Applicable

Applicable

private

Not Applicable

Applicable

Applicable

protected

Not Applicable

Applicable

Applicable

abstract

Applicable

Applicable

Not Applicable

final

Applicable

Applicable

Not Applicable



Leave a comment