Created
March 30, 2015 16:23
-
-
Save johnsonch/2f42d8e84b82aa1fb7c4 to your computer and use it in GitHub Desktop.
PHP getter and setter example for class
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 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