From fd42737b1ddc1ee3f5e975530e0aed10b5d31868 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imun=20Gogi=C4=87?= Date: Mon, 19 Nov 2018 14:56:38 +0100 Subject: [PATCH] Added description of class sections (#22306) Added description for class definition, instance variables, setter and getter functions, creation of instance and calling a function on it --- guide/english/php/class/index.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/guide/english/php/class/index.md b/guide/english/php/class/index.md index b753240aa9..8b4ed6377f 100644 --- a/guide/english/php/class/index.md +++ b/guide/english/php/class/index.md @@ -5,14 +5,14 @@ title: PHP - Class ### Simple Class for Beginner! ```php -class Lab { - private $name = ''; +class Lab { // class keyword is mandatory identifier for class creation, after class keyword goes the name of the class(e.g. Lab) + private $name = ''; // $name is instance variable, which means that every instantiated object has it's own copy of variable $name - public function setName($name) { - $this->name = $name; - } + public function setName($name) { // function setName is setter function that sets the value of instance variable $name + $this->name = $name; // because $name is the name of both instance variable and function parameter, we use $this keyword + } - private function getName() { + private function getName() { // getName is getter function that returns the value of instance variable $name return $this->name; } @@ -23,7 +23,7 @@ class Lab { } $breaking_bad = 'Heisenberg'; -$lab = new Lab(); -$lab->setName($breaking_bad); +$lab = new Lab(); // keyword new creates instance of Lab class, variable $lab points to that instance +$lab->setName($breaking_bad); // $lab variable that points to Lab instance calls setter function setName with $breaking_bad as parameter echo "My Name is " . $lab->say_my_name(). "!"; ```