PHP Encapsulation
In PHP, encapsulation is the process of binds together the data and methods in a single unit. It's safe from outside interference and misuse.
Example: Capsule, it is wrapped with different medicines.

Data encapsulation is the process of binding the data, and the methods that use them and data abstraction is the process of showing only the interfaces and hiding the implementation details from the user.
The primary goal of encapsulation is the insulation of a particular object class internal detail and show the interfaces.
If the data member is declared Private then it accesses within that package or class only.
Example:
<?php class Book { private $bookname; // Getter method public function getName() { return $this->bookname; } // Setter method public function setName($bookname) { $this->bookname = $bookname; } } // Main logic $b = new Book(); $b->setName("Onlinetpoint"); echo $b->getName(); ?>
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.