How do you achieve data encapsulation in PHP? Give an Example.
Answer:
Encapsulation is just wrapping some data in an object. The term "encapsulation" is often used interchangeably with "information hiding"
Example
<?php
class App{
private static $_user{
public function User(){
if($this->_user==null){
$this->_user = new User();
}
return $this->_user
}
}
class User{
private $_name;
public function_construct(){
$this-> = "GetWays"
}
public function GetName(){
return $this->_name;
}
}
$app = new App();
echo $app->User()->GetName()
?>
Other Question With Answer
Write a PHP program to create a class student with the following specification data member name roll number average marks member function read and write use the above specifications to read and print the informations of 2 students
ReplyDelete