Category: PHP

  • 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. Create a Static Method in PHP In a class…

  • Traits

    When designing websites with PHP, you might want to share the same functionality among different classes. However, PHP does not support multiple inheritance. A class can only inherit from one parent class. So, how do you reuse code between classes? In PHP, Traits have been introduced to overcome this limitation. You can define one or…

  • 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.…

  • Abstract Classes

    An abstract class in PHP is a class that cannot be created on its own. This means you can’t create objects straight from an abstract class. Abstract classes are intended to be extended by subsequent classes. They serve as a blueprint for other classes, defining the common methods and properties that inheriting classes must implement.…

  • Class Constants

    PHP allows an identifier in a class to be defined as a “class constant” with a constant value, the one that remains unchanged on a per class basis. To differentiate from a variable or property within class, the name of the constant is not prefixed with the usual “$” symbol and is defined with the…

  • Inheritance

    Inheritance is one of the fundamental principles of object-oriented programming methodology. Inheritance is a software modelling approach that enables extending the capability of an existing class to build new class instead of building from scratch. PHP provides all the functionality to implement inheritance in its object model. Incorporating inheritance in PHP software development results in…

  • Access Modifiers

    In PHP, the keywords public, private and protected are known as the access modifiers. These keywords control the extent of accessibility or visibility of the class properties and methods. One of these keywords is prefixed while declaring the member variables and defining member functions. Access Modifiers in PHP Whether the PHP code has free access to a class member, or…

  • Constructor and Destructor

    As in most of the object-oriented languages, you can define a constructor function in a class in PHP also. When you declare an object with the new operator, its member variables are not assigned any value. The constructor function is used to initialize every new object at the time of declaration. PHP also supports having…