Encapsulation in PHP

Advertisements

Abstraction in PHP Polymorphism in PHP

Encapsulation in PHP

It is a concept of wrapping up or binding up related data members and methods in a single module known as Encapsulation. Encapsulation refers to a concept where we encapsulate all the data and member functions together to form an object.

Syntax

<?php

class person
{
public $name;
public $age;
 
function __construct($n, $a)
 {
$this->name=$n;
$this->age=$a;
 
}
 
public function setAge($ag)
{
$this->ag=$ag;
}
 
public function display()
{
echo  "welcome ".$this->name."
"; return $this->age-$this->ag; } } $person=new person("Gaurav",27); $person->setAge(20); echo "You are ".$person->display()." years old"; ?>

Output

welcome Gaurav You are 28 years old

Abstraction in PHP Polymorphism in PHP

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements