<?php
class Rectangle
{
    public $type, $a, $b;
    public $area = 0;
    public function Calc_rect_area()
    {
        $this->area= $this->a * $this->b;
    }
}

class Circle
{
    public $type, $radius;
    public $area = 0;
    public function Calc_circle_area()
    {
        $this->area = $this->radius * $this->radius * 3.14;
    }
}

class Pyramid
{
    // длина основания, ширина основания, длина стороны
    public $type,$a, $b, $c;
    public $area = 0;
    public function Calc_pyram_area()
    {
        $checkPyr = 2 * $this->c - $this->a - $this->b; //проверяем стороны пирамиды
        if ($checkPyr < 0) {
            return 0; //пирамида не омжет существовать
        } elseif ($checkPyr == 0) {
            return $this->a * $this->b; //вершина пирамиды находится на плоскости основания, то есть получился прямоугольник
        } else {
            $firstTriangleArea = $this->b / 4 * sqrt(4 * $this->c * $this->c - $this->b * $this->b);
            $secondTriangleArea = $this->a / 4 * sqrt(4 * $this->c * $this->c - $this->a * $this->a);
            $this->area = $this->a * $this->b + 2 * $firstTriangleArea + 2 * $secondTriangleArea;
        }
    }
}

$figures = Create_figures();//запускаем функцию создания фигур \
//sort
Show_figures($figures);     //выводим типы созданных фигур

//далее мы создаем 5 фигур с рандомнями полями, рандомных типов, считаем их площади
function Create_figures()
{
    $figures = [];
    for ($i=0; $i<5; $i++){
        $typeID = rand(0,3);
        if ($typeID == 0) {
            $figure = new Rectangle();
            $figure->type = "Rectangle";
            $figure->a = rand(1,10);
            $figure->b = rand(1,10);
            $figure->Calc_rect_area();
            $figure->area;

        } elseif ( $typeID == 1) {
            $figure = new Circle();
            $figure->type = "Circle";
            $figure->radius = rand(1,10);
            $figure->Calc_circle_area();
            $figure->area;

        } else {
            $figure = new Pyramid();
            $figure->type = "Pyramid";
            $figure->a = rand(1,10);
            $figure->b = rand(1,10);
            $figure->c = rand(1,10);
            $figure->Calc_pyram_area();
            $figure->area;
        }
        $figures[] = $figure;

    }
    return $figures;
}

//далее функция для вывода типов фигур перебором
function Show_figures($figures) {
    $number = 1;
    foreach ($figures as $figure) {
        if ($figure->type == "Rectangle") {
            echo "{$number}.{$figure->type}, площадь фигуры {$figure->area}<br/>";
        } elseif ($figure->type == "Circle") {
            echo "{$number}.{$figure->type}, площадь фигуры {$figure->area}<br/>";
        } else {
            echo "{$number}.{$figure->type}, площадь фигуры {$figure->area}<br/>";
        }
        $number++;
    }
}

?>