Skip to content

Instantly share code, notes, and snippets.

@buiquangduc
Created September 26, 2017 02:15
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 buiquangduc/9b0f5ca38fffbb8b0bfb0ec6802ed0a4 to your computer and use it in GitHub Desktop.
Save buiquangduc/9b0f5ca38fffbb8b0bfb0ec6802ed0a4 to your computer and use it in GitHub Desktop.
Don't expose member data in public
<?php
// Example of exposing member data in public
// Coding Horror
class Class
{
public $student;
public $teacher;
}
// Example of good encapsulation (don't expose member data in public)
class Class
{
protected $student;
protected $teacher;
public function setStudent($student) {
$this->student = $student;
}
public function setTeacher($teacher) {
$this->teacher = $teacher;
}
public function getStudent() {
return $this->student;
}
public function getTeacher() {
return $this->teacher;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment