Last active
February 13, 2019 17:30
-
-
Save arif98741/d8bc700846a3cc07626c1d4c78208a82 to your computer and use it in GitHub Desktop.
PHP OOP Error Solve
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 | |
/* | |
! I updated your class and its description. I am oop lover. | |
! @Class Distance | |
! @pvt variable | |
! @ always use description and intro . It will help you to edit code in future | |
*/ | |
class Distance //class name should always be Capital. Its good practice | |
{ | |
private $string1; | |
private $string2; | |
/* | |
!-------------------------------------- | |
! Initialize Constructor | |
!-------------------------------------- | |
*/ | |
public function __construct($string1, $string2) | |
{ | |
$this->string1 = $string1; | |
$this->string2 = $string2; | |
} | |
/* | |
!-------------------------------------- | |
! Set Variable Value String1 | |
! @param string | |
!-------------------------------------- | |
*/ | |
public function setString1($string1) | |
{ | |
$this->string1 = $string1; | |
} | |
/* | |
!-------------------------------------- | |
! Set Variable Value String2 | |
! @param string | |
!-------------------------------------- | |
*/ | |
public function setString2($string2) | |
{ | |
$this->string2 = $string2; | |
} | |
/* | |
!-------------------------------------- | |
! Get Variable Value String1 | |
! @return string | |
!-------------------------------------- | |
*/ | |
public function getString1() | |
{ | |
//echo $this->string1; | |
return $this->string1; | |
} | |
/* | |
!-------------------------------------- | |
! Get Variable Value String2 | |
! @return string | |
!-------------------------------------- | |
*/ | |
public function getString2() | |
{ | |
return $this->string2; | |
} | |
/* | |
!-------------------------------------- | |
! Calculate Distance | |
!-------------------------------------- | |
*/ | |
protected function calculateDistance($str1, $str2) | |
{ | |
// echo "calculateDistance"; //what have you done here actually? | |
} | |
/* | |
!-------------------------------------- | |
! Get Distance | |
!-------------------------------------- | |
*/ | |
public function getDistance($str1, $str2) | |
{ | |
$result = $this->calculateDistance($str1, $str2); | |
return $result; | |
} | |
} | |
$test2 = new distance("hello", "world"); | |
$t4 = $test2->getString1(); | |
$t5 = $test2->getString2(); | |
echo $t4 . " " . $t5; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment