CLASSES and objects – Two main aspects of object- oriented programming.
A Class - is a template for object, and an Object is an instance of a class.
two methods set_name() and get_name() for setting and getting the $name property.
Objects of a class are created using the new keyword.
Classes are nothing without objects! We can create multiple objects from a class. Each object has all the properties and methods defined in the class, but they will have different property values.
In PHP, public, protected, and private are access modifiers that define the visibility of properties and methods in a class. These modifiers determine from where the properties and methods can be accessed.
Public - Properties or methods declared as public can be accessed from outside the class, that is, they are visible everywhere, including outside the class and its subclasses.
Protected - Properties or methods declared as protected are accessible within the class and its subclasses. They are not directly accessible from outside the class.
Private - Properties or methods declared as private are only accessible within the class itself. They are not visible or accessible from outside the class, including its subclasses.
Local Variable Scope - are declared within a function and can only be accessed within that function.
Global Variable Scope - Global variables are declared outside of any function and can be accessed from any part of the script.
Encapsulation - is one of the fundamental principles of Object-Oriented Programming (OOP) and involves bundling the data (attributes or properties) and methods (functions) that operate on the data into a single unit, which is called a class.
Encapsulation - Additionally, it restricts direct access to some of the object's components and hides the internal details, exposing only what is necessary.
encapsulation can be achieved using access modifiers such as public, protected, and private.
Encapsulation - helps in maintaining a clear and consistent state of the object and provides a level of abstraction, making it easier to manage and modify the internal implementation without affecting the external code that uses the class.
Object-OrientedProgramming (OOP) - allows you to use classes and objects to organize your code in a more modular and reusable way.
Inheritance - is a fundamental concept in OOP that allows a class (subclass or derived class) to inherit properties and methods from another class (superclass or base class).
inheritance - is a mechanism that allows a new class (subclass or derived class) to inherit properties and behaviors from an existing class (superclass or base class)
Inheritance - enables a subclass to use the attributes and methods of a superclass, allowing the subclass to specialize or extend the functionality of the superclass.
Base Class (Superclass): The class whose properties and methods are inherited by another class is called the
Derived Class (Subclass): The class that inherits properties and methods from another class is called .
public: Inherited properties and methods are accessible from outside the subclass.
protected: Inherited properties and methods are accessible within the subclass and its subclasses.
private: Inherited properties and methods are not accessible in the subclass; only the public and protected members are inherited.
polymorphism - is a concept that allows objects of different classes to be treated as objects of a common base class.
Polymorphism enables a single interface to be used for a general set of actions, making it possible to work with objects of various types in a consistent manner.
There are two main types of polymorphism in OOP: compile-time(or static) polymorphism and runtime (or dynamic) polymorphism.
Compile-time (Static) Polymorphism Also known as method overloading or function overloading.
Compile-time (Static) Polymorphism - Involves defining multiple methods in a class with the same name but different parameter lists.
Runtime (Dynamic) Polymorphism Also known as method overriding.
Runtime (Dynamic) Polymorphism - Involves creating a relationship between a base class and a derived class, where the derived class provides a specific implementation of a method declared in the base class.
Polymorphism- can be achieved through both method overloading and method overriding.
Method overriding - allowing a subclass to provide a specific implementation of a method defined in its parent class.
Abstraction - involves creating abstract classes and methods that define a blueprint for other classes to follow.
Abstraction - allows you to hide the implementation details and focus on the essential characteristics of an object.
Abstraction - is achieved using abstract classes and abstract methods.
Enumerate the Data types : STRING, FLOAT , BOOLEAN, ARRAY , NULL, RESOURCE , OBJECT, INTEGER.
String - is a sequence of characters, like "Hello world!".
String- can be any text inside quotes. You can use single or double quotes.
Var_dump() - function returns the data type and value.