itmo-php-course/Koterov-php-training/classes_and_objects/PointClass/index.php

111 lines
2.0 KiB
PHP

<?php
require 'point.php';
$point = new Point;
// var_dump($point->x);
$point->x = 5;
$point->y = 3.2;
echo '<pre>';
print_r($point);
echo '</pre>';
echo "<br/>";
echo $point->x;
echo "<br/>";
echo $point->y;
echo "<br/>";
echo gettype($point);
echo "<br/>";
echo get_class($point);
echo "<br/>";
echo "<br/>";
echo ($point ->x ** 2 + $point ->y ** 2) ** 0.5 . ' - Такое вот вычисление';
echo "<br/>";
// Уничтожение объекта
// unset($point);
// echo $point->x;
require_once('private_point.php');
$prpoint = new PrivatePoint;
$prpoint->x = 3;
echo $prpoint->x;
echo "<br/>";
echo gettype($prpoint);
echo "<br/>";
echo get_class($prpoint);
echo "<br/>";
echo "<br/>";
echo ($prpoint ->x ** 2 + $point ->y ** 2) ** 0.5 . ' - Такое вот вычисление';
echo "<br/>";
echo "<br/>";
require_once('readonly.php');
$obj = new Greating;
echo $obj->setter();
echo "<br/>";
echo "Hello $obj->hello";
echo "<br/>";
echo "<br/>";
require_once('readonly_construct.php');
$object = new GreatingConst();
echo "Hello construct $object->hello";
echo "<br/>";
echo gettype($object);
echo '<pre>';
print_r($object);
echo '</pre>';
echo "<br/>";
require_once("my_static.php");
echo "Статическая переменная: ". MyStatic::$staticvar;
echo "<br/>";
echo "<br/>";
// $first = $second = 1;
// $first = 3;
// echo $second;
// echo "<br/>";
// echo "<br/>";
// echo $first;
// echo "<br/>";
// echo "<br/>";
$first = new Point;
$first->x = 3;
$first->y = 3;
$second = $first;
$second->x = 5;
$second->y = 5;
echo "x: {$first->x}, y: {$first->y}";
echo "<br/>";
echo "<br/>";
$firstvar = 5;
$secondvar = &$firstvar;
$secondvar = 1;
echo $firstvar;
echo "<br/>";
echo "<br/>";
$secondclone = clone $first;
$secondclone->x = 9;
$secondclone->y = 9;
echo "Объект first до клонирования - x: {$first->x}, y: {$first->y}";
echo "<br/>";
echo "<br/>";
echo "Объект first после клонирования - x: {$secondclone->x}, y: {$secondclone->y}";