itmo-php-course/Koterov-php-training/methods_of_classes/point.php

46 lines
840 B
PHP

<?php
class Point
{
// private $x;
// private $y;
public function __construct(private int $x = 0, private int $y = 0)
{
echo 'Вызов конструктора <br />';
$this->x = $x;
$this->y = $y;
}
public function inner()
{
$this->__construct();
}
// public function setX(int $x): void
// {
// $this->x = $x;
// }
// public function setY(int $y): void
// {
// $this->y = $y;
// }
public function getX(): int
{
return $this->x;
}
public function getY(): int
{
return $this->y;
}
public function distance(): float
{
return sqrt($this->getX() ** 2 + $this->getY() ** 2);
}
public function listVariables(): array
{
return get_object_vars($this);
}
}