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 '
';
 print_r($point->listVariables());
-echo '
'; \ No newline at end of file +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 'Вызов деструктора
'; + } } \ No newline at end of file diff --git a/Koterov-php-training/methods_of_classes/rainbow.php b/Koterov-php-training/methods_of_classes/rainbow.php new file mode 100644 index 0000000..81737e2 --- /dev/null +++ b/Koterov-php-training/methods_of_classes/rainbow.php @@ -0,0 +1,23 @@ + 'красный', + 'orange'=> 'ранжевый', + 'yellow'=> 'жёлтый', + 'green'=> 'зелёный', + 'blue'=> 'голубой', + 'indigo'=> 'синий', + 'violet'=> 'фиолетовый', + ]; + + public function __get(string $key): ?string + { + if (array_key_exists($key, Rainbow::COLORS)) { + return Rainbow::COLORS[$key]; + } else { + return null; + } +} +} diff --git a/cristmass-tree/index.php b/cristmass-tree/index.php index 0ffa44a..ce11aba 100644 --- a/cristmass-tree/index.php +++ b/cristmass-tree/index.php @@ -2,5 +2,5 @@ include_once ('tree.php'); -$cristmassTree = new Tree(15); +$cristmassTree = new Tree(50); $cristmassTree->drawTree();