Tag learn php in one day

PHP OOP – Static Properties

PHP – Static Properties Static properties can be called directly – without creating an instance of a class. Static properties are declared with the static keyword: Syntax <?php class ClassName {   public static $staticProp = “iampsp”; } ?> To…

PHP OOP – Static Methods

PHP – Static Methods Static methods can be called directly – without creating an instance of the class first. Static methods are declared with the static keyword: Syntax <?php class ClassName {   public static function staticMethod() {     echo…

PHP OOP – Traits

PHP – What are Traits? PHP only supports single inheritance: a child class can inherit only from one single parent. So, what if a class needs to inherit multiple behaviors? OOP traits solve this problem. Traits are used to declare…

PHP OOP – Interfaces

PHP – What are Interfaces? Interfaces allow you to specify what methods a class should implement. Interfaces make it easy to use a variety of different classes in the same way. When one or more classes use the same interface,…

PHP OOP – Abstract Classes

PHP – What are Abstract Classes and Methods? Abstract classes and methods are when the parent class has a named method, but need its child class(es) to fill out the tasks. An abstract class is a class that contains at…

PHP OOP – Class Constants

PHP – Class Constants Class constants can be useful if you need to define some constant data within a class. A class constant is declared inside a class with the const keyword. A constant cannot be changed once it is…

PHP OOP – Inheritance

PHP – What is Inheritance? Inheritance in OOP = When a class derives from another class. The child class will inherit all the public and protected properties and methods from the parent class. In addition, it can have its own…

PHP OOP – Access Modifiers

PHP – Access Modifiers Properties and methods can have access modifiers which control where they can be accessed. There are three access modifiers: public – the property or method can be accessed from everywhere. This is default protected – the…

PHP OOP – Destructor

PHP – The __destruct Function A destructor is called when the object is destructed or the script is stopped or exited. If you create a __destruct() function, PHP will automatically call this function at the end of the script. Notice…