Skip to content

Instantly share code, notes, and snippets.

@johnsonch
Created March 30, 2015 16:23
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 johnsonch/2f42d8e84b82aa1fb7c4 to your computer and use it in GitHub Desktop.
Save johnsonch/2f42d8e84b82aa1fb7c4 to your computer and use it in GitHub Desktop.
PHP getter and setter example for class
<?php
class myClass{
private $propertyA
private $propertyB
public function getPropertyA(){
return $this->propertyA;
}
public function setPropertyA($value){
$this->propertyA = $value;
}
public function getPropertyB(){
return $this->propertyB;
}
public function setPropertyB($value){
$this->propertyB = $value;
}
}
$instance = new myClass;
$instance.setPropertyA('foo');
echo $instance.getPropertyA(); // foo
$instance.setPropertyB('bar');
echo $instance.getPropertyB(); // bar
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment