Created
July 12, 2016 12:41
-
-
Save pssubashps/b00b4702cd2a77a1e677f3def2382177 to your computer and use it in GitHub Desktop.
Private Access Specifier in PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Employees { | |
private $fistname; | |
private $lastname; | |
/** | |
* public variable | |
**/ | |
public $organization ; | |
function __construct() { | |
$this->organization = 'Nidhi Infotech'; | |
$this->lastname = "John"; | |
$this->firstname = "Smith"; | |
} | |
/** | |
* To get organization name | |
**/ | |
public function getOrganization(){ | |
return $this->organization; | |
} | |
/** | |
* Memeber functin can access private property | |
**/ | |
public function getName() { | |
return $this->lastname.", ".$this->firstname; | |
} | |
} | |
$emp = new Employees; | |
/** | |
* this wil throw wrror E_ERROR : type 1 -- Cannot access private property Employees::$fistname | |
* echo $emp->fistname; | |
* | |
**/ | |
echo $emp->getName(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment