PHP Abstraction
Hiding the details of the object and showing the functionality is called as an abstraction.
In PHPdata abstraction refers to providing only essential information to the outside world and hiding the internal details.
Example: Phone call, we do not know the internal processing.

Advantages of Data Abstraction
- Implementation details of the class are protected from the unexpected user-level errors, which corrupt the state of the object.
- It helps to avoids the code duplication.
- It helps to reuse the code and provide partitioning of the code across the classes.
Abstract Class
A class which has declared as abstract is known as an abstract class. It has abstract methods and non-abstract methods. An abstract class consist of declaration as well as definition. It is a class that can't instantiated.
An abstract class is used as a base class for the deriving purpose only. An abstract class can't create an object.
abstract class A{ //Abstract methods //Non-Abstract methods }
Abstract Method
A method which has declared as abstract and it doesn't have implementation details is known as an abstract method.
abstract void method_name();//no method body
Example:
<?php // Abstract class abstract class Shape { abstract public function draw(); } // Rectangle class extends Shape class Rectangle extends Shape { public function draw() { echo "Drawing of the rectangle\n"; } } // Circle class extends Shape class Circle extends Shape { public function draw() { echo "Drawing of the circle\n"; } } // Main execution $s = new Circle(); $s1 = new Rectangle(); $s->draw(); $s1->draw(); ?>
Quickly Find What You Are Looking For
OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.