PHP OOP – Static Methods

Before moving to static methods let’s see the instance method. To utilize the class’s methods and properties, you must first construct an object and then use the object to access the class’s methods and properties. These methods and properties are referred to as instance methods and properties because they are tied to a specific instance … Read more

PHP OOP-Static Properties

Just like Static methods, Static properties can be called without having to create a class instance first. The static keyword is used to declare static methods: Static properties can be called from outside the class using the class name and the scope resolution operator (::), as seen below: Consider the following scenario: Static properties: Self Keyword: … Read more

PHP MySQL Database

The most often used database system with PHP is MySQL. MySQL: MySQL is a relational database management system that is free and open-source. The MySQL database system has a number of advantages: It is open-source and easy to install. MySQL is compatible with UNIX or Linux, Microsoft Windows and other operating systems. It is fast, … Read more

PHP – OOP

PHP-OOP is more efficient and simpler to use. PHP -What is OOP? Object-oriented programming is about constructing objects that include both data and functions, whereas procedural programming is about developing procedures or functions that perform actions on the data. There are various advantages of OOP over procedural programming: OOP programmes have a clear structure. It … Read more

PHP OOP- Class and Object

A class is an independent set of variables and functions that interact to complete one or more tasks. Basically class is a template for multiple objects. While individual instances of a class are called objects. Class and Object Class Object A class is an independent set of variables and functions that interact to complete one or more … Read more

PHP OOP Constructor

Constructors are functions used for creating newly created object instances from a class. When creating an object, the constructor function is used to set the object’s properties. When you create an object from a class, PHP will automatically call the __construct() function you defined. Constructor Syntax: It is a public function that is written as … Read more

PHP OOP Destructor

When an object destructs, destructors are called. It’s usually when the script comes to an end. The destruct function is called at the end of the script. Note: Constructor and destructor both are used to reduce the code so they are useful. Destructor Syntax: The destructor function is named destruct and is followed by a double … Read more

PHP OOP – Encapsulation

Encapsulation allows us to hide properties and methods within a class such that they are not accessible by other classes. In PHP access modifiers are used for encapsulation, these modifiers are simply PHP keywords, to set the access permissions for class methods and variables. Some of the access modifiers can even be applied to the class … Read more

PHP OOP – Traits

In PHP multiple inheritance is not supported, which implies a child class can only have one parent class. Traits allow you to easily reuse methods across several classes that don’t have to be in the same hierarchy. Traits allow classes to reuse code horizontally, whereas inheritance allows reusing code vertically. Methods that can be utilized across … Read more

PHP OOP-Class Constants

Constants are bits of data saved in the computer’s memory that can not be modified once they have been assigned. Constants declared within classes are known as class constants. Declaring Class Constants A class constant is declared with the const keyword. Class constant must be declared inside class. Note: Class constants are case-sensitive. It is preferred that … Read more