Category: 12. PHP
-
Overloading
In C++ or Java, the term means a class can a class method of same name more than once but with different arguments and/or return type. In PHP, the term overloading has a different interpretation. It is a feature with which properties and methods can be created dynamically. PHP’s magic methods (method names starting with…
-
The “Final” Keyword
The “final” keyword in PHP is used in the definition of a class, a method inside a class, as well as with the definition of a constant property of a class. A Class with “final” Keyword Let’s see how to create a class with the “final” keyword − The “final” keyword in class definition prevents…
-
Encapsulation
PHP implements encapsulation, one of the important principles of OOP with access control keywords: public, private and protected. Encapsulation refers to the mechanism of keeping the data members or properties of an object away from the reach of the environment outside the class, allowing controlled access only through the methods or functions available in the class. The following diagram…
-
Encapsulation
PHP implements encapsulation, one of the important principles of OOP with access control keywords: public, private and protected. Encapsulation refers to the mechanism of keeping the data members or properties of an object away from the reach of the environment outside the class, allowing controlled access only through the methods or functions available in the class. The following diagram…
-
Object Iteration
A foreach loop may be employed to iterate through all the publicly visible members of an object of a PHP class. This feature has been available in versions of PHP 5 onwards. You can of course access the list of private properties inside an instance method. PHP also defines Iterator interface which can be used for the…
-
Namespaces
We often organize the files in different folders. Usually a folder contains files related to a certain objective, or application or category. A folder can’t contain two files with the same name, though different folders may have a file of the same name so that the path of each file is different. The idea of…
-
Static Properties
The “static” keyword in PHP is used to define static properties and static methods in a PHP class. It may be noted that the static keyword is also used to define static variable, and static anonymous functions. Read this chapter to learn about the static properties in a PHP class. In a class definition, a…
-
Static Methods
The “static” keyword in PHP is used to define static properties and static methods in a PHP class. It may be noted that the static keyword is also used to define static variable, and static anonymous functions. This chapter discusses static methods in a PHP class. In a class definition, a function declared with a…
-
Traits
In PHP, a class can inherit only from one parent class, multiple inheritance is not defined in PHP. Traits in PHP have been introduced to overcome this limitation. You can define one or more method in a trait, which can be reused freely in various independent classes. Syntax The “trait” keyword is used as per…
-
Interfaces
Just as a class is a template for its objects, an interface in PHP can be called as a template for classes. We know that when a class is instantiated, the properties and methods defined in a class are available to it. Similarly, an interface in PHP declares the methods along with their arguments and return value.…