Пример #1
0
 protected function generateNumbers()
 {
     for ($i = 0; $i < $this->currentAmount;) {
         $singleBall = Ball::generateBall();
         if (!isset($this->content[$singleBall])) {
             $this->content[$singleBall] = $singleBall;
             $i++;
         }
     }
     usort($this->content, "strnatcmp");
 }
<?php

abstract class Toy
{
    public function ping()
    {
        return 'pong';
    }
}
class Ball extends Toy
{
    public function roll()
    {
        parent::ping();
        return 'rolling';
    }
}
$b = new Ball();
$b->roll();
Пример #3
0
        parent::__construct($a, $p, $name);
    }
    public function V()
    {
        return $this->a * $this->h * $this->h_o / 6;
    }
}
class Parallelepiped extends Figure
{
    private $b;
    private $c;
    function __construct($a, $b, $c, $p, $name)
    {
        $this->b = $b;
        $this->c = $c;
        parent::__construct($a, $p, $name);
    }
    public function V()
    {
        return $this->a * $this->b * $this->c;
    }
}
$cube = new Cube(4, 5, "Куб");
$ball = new Ball(3, 5, "Куля");
$pyramid = new Pyramid(3, 5, 7, 5, "Піраміда");
$parallelepiped = new Parallelepiped(4, 5, 6, 5, "Паралелипіпит");
$c = $cube->name . ": " . "Об’єм = " . $cube->V() . "; " . "Маса = " . $cube->mass() . "; " . "Густина = " . $cube->p . "\n";
$b = $ball->name . ": " . "Об’єм = " . $ball->V() . "; " . "Маса = " . $ball->mass() . "; " . "Густина = " . $ball->p . "\n";
$p = $pyramid->name . ": " . "Об’єм = " . $pyramid->V() . "; " . "Маса = " . $pyramid->mass() . "; " . "Густина = " . $pyramid->p . "\n";
$a = $parallelepiped->name . ": " . "Об’єм = " . $parallelepiped->V() . "; " . "Маса = " . $parallelepiped->mass() . "; " . "Густина = " . $parallelepiped->p . "\n";
echo $c, $b, $p, $a;