Skip to content

Instantly share code, notes, and snippets.

@pssubashps
Created July 12, 2016 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pssubashps/b00b4702cd2a77a1e677f3def2382177 to your computer and use it in GitHub Desktop.
Save pssubashps/b00b4702cd2a77a1e677f3def2382177 to your computer and use it in GitHub Desktop.
Private Access Specifier in PHP
<?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