What is encapsulation with simple example in php?
Encapsulation is a way of storing an object or data as a property within another object, so that the outer object has full control over what how the internal data or object can be accessed.
For example
class OuterClass
{
private var $innerobject;
function increment()
{
return $this->innerobject->increment();
}
}
You have an extra layer around the object that is encapsulated, which allows the outer object to control how the inner object may be accessed. This, in combination with making the inner object/property private, enables information hiding.