Created
November 19, 2014 14:16
-
-
Save Webbist-dev/0b0f2472c90ccfe624a2 to your computer and use it in GitHub Desktop.
First php class and object usage
This file contains 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
class Person { | |
public $teacher; | |
public $student; | |
public $age; | |
function displayStudentNameandTeacher() { | |
echo 'My Name is ' . $this->student . ' my teacher is ' . $this->teacher . '. My teachers age is ' . $this->getAge() . '.'; | |
} | |
function setAge($var) { | |
$this->age = $var; | |
} | |
function getAge() { | |
return $this->age; | |
} | |
} | |
$obj1 = new Person(); | |
$obj1->setAge(25); | |
$obj1->teacher = "Mrs Williams"; | |
$obj1->student = "Alex Bennett"; | |
$obj1->displayStudentNameandTeacher(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment