diff --git a/Koterov-php-training/methods_of_classes/index.php b/Koterov-php-training/methods_of_classes/index.php index de647cf..c466344 100644 --- a/Koterov-php-training/methods_of_classes/index.php +++ b/Koterov-php-training/methods_of_classes/index.php @@ -25,7 +25,7 @@ echo ""; var_dump( $point->getY()); echo ""; -echo $point->distance(); +echo $point->distance; echo '
'; print_r($point); @@ -53,4 +53,14 @@ $point->z = 5; echo ''; + +require_once ('rainbow.php'); + +$rainbow = new Rainbow; +echo $rainbow->yellow; +echo ""; +echo $rainbow->red; +echo ""; +echo $rainbow->unknown; +echo ""; \ No newline at end of file diff --git a/Koterov-php-training/methods_of_classes/point.php b/Koterov-php-training/methods_of_classes/point.php index e7638c1..18bc15e 100644 --- a/Koterov-php-training/methods_of_classes/point.php +++ b/Koterov-php-training/methods_of_classes/point.php @@ -24,6 +24,15 @@ class Point // { // $this->y = $y; // } + + public function __get($key) + { + if ($key === 'distance') { + return sqrt($this->getX() ** 2 + $this->getY() ** 2); + } else { + return null; + } + } public function getX(): int { return $this->x; @@ -32,15 +41,14 @@ class Point { return $this->y; } - public function distance(): float - { - return sqrt($this->getX() ** 2 + $this->getY() ** 2); - } public function listVariables(): array { return get_object_vars($this); } - + public function __destruct() + { + echo 'Вызов деструктора'; print_r($point->listVariables()); -echo ''; \ No newline at end of file +echo '