{ public function draw() { print "Inside Rectangle::draw method.\n"; // 'print' works too } } $we = new Employee('Bob', 'Diamond'); echo $we->greeting(); echo PHP_EOL; $we->foo(); // overriding seems to work $he->foo(); $rect = new Rectangle(); // or 'new Rectangle()' $rect->draw(); echo empty(""); echo PHP_EOL; echo null == NULL; echo PHP_EOL; // PHP Arrays are in fact associative arrays, i.e. Map and Dictionaries $myArray = ["1" => "Hello", "2" => "How are you?", "3" => "Very well ty"]; $yourArray = []; echo $myArray["1"] . PHP_EOL; echo $myArray["2"] . PHP_EOL; echo $myArray["3"] . PHP_EOL; $myArray["4"] = "This is a new item"; echo $myArray["4"] . PHP_EOL; echo $myArray["4"] . PHP_EOL; var_dump($myArray); $x = ["a", "b", "c"];
private $radius; public function __construct($x, $y, $radius) { parent::__construct($x, $y); $this->radius = $radius; } protected function drawShape() { return "Рисуем окружность с радиусом {$this->radius}"; } } class Rectangle extends Shape { private $width; private $height; public function __construct($x, $y, $width, $height) { parent::__construct($x, $y); $this->width = $width; $this->height = $height; } protected function drawShape() { return "Рисуем прямоугольник с шириной {$this->width} и высотой {$this->height}"; } } $circle = new Circle(0, 0, 50); $rectangle = new Rectangle(0, 0, 100, 50); $circle->draw(); $rectangle->draw();
function draw($image) { $this->bound->normalize(); $depth = $this->depth; if ($this->surfaces & self::SURFACE_BOTTOM) { $points = [$this->bound->left(), $this->bound->bottom(), $this->bound->left() + $depth, $this->bound->bottom() - $depth, $this->bound->right() + $depth, $this->bound->bottom() - $depth, $this->bound->right(), $this->bound->bottom()]; imagefilledpolygon($image, $points, 4, $this->bgcolor->resolve($image)); if ($this->fgcolor !== NULL) { imagepolygon($image, $points, 4, $this->fgcolor->resolve($image)); } } if ($this->surfaces & self::SURFACE_BACK) { $points = [$this->bound->left() + $depth, $this->bound->bottom() - $depth, $this->bound->left() + $depth, $this->bound->top() - $depth, $this->bound->right() + $depth, $this->bound->top() - $depth, $this->bound->right() + $depth, $this->bound->bottom() - $depth]; imagefilledpolygon($image, $points, 4, $this->bgcolor->resolve($image)); if ($this->fgcolor !== NULL) { imagepolygon($image, $points, 4, $this->fgcolor->resolve($image)); } } if ($this->surfaces & self::SURFACE_LEFT) { $points = [$this->bound->left(), $this->bound->bottom(), $this->bound->left(), $this->bound->top(), $this->bound->left() + $depth, $this->bound->top() - $depth, $this->bound->left() + $depth, $this->bound->bottom() - $depth]; imagefilledpolygon($image, $points, 4, $this->bgcolor->resolve($image)); if ($this->fgcolor !== NULL) { imagepolygon($image, $points, 4, $this->fgcolor->resolve($image)); } } if ($this->surfaces & self::SURFACE_RIGHT) { $points = [$this->bound->right(), $this->bound->top(), $this->bound->right() + $depth, $this->bound->top() - $depth, $this->bound->right() + $depth, $this->bound->bottom() - $depth, $this->bound->right(), $this->bound->bottom()]; imagefilledpolygon($image, $points, 4, $this->bgcolor->resolve($image)); if ($this->fgcolor !== NULL) { imagepolygon($image, $points, 4, $this->fgcolor->resolve($image)); } } if ($this->surfaces & self::SURFACE_TOP) { $points = [$this->bound->left(), $this->bound->top(), $this->bound->left() + $depth, $this->bound->top() - $depth, $this->bound->right() + $depth, $this->bound->top() - $depth, $this->bound->right(), $this->bound->top()]; imagefilledpolygon($image, $points, 4, $this->bgcolor->resolve($image)); if ($this->fgcolor !== NULL) { imagepolygon($image, $points, 4, $this->fgcolor->resolve($image)); } } if ($this->surfaces & self::SURFACE_FRONT) { parent::draw($image); } }