SA
<?php
interface Resizable {
public function width(): int;
public function setWidth(int $arg);
}
interface Named {
public function name(): string;
}
class Widget implements Named, Resizable {
private $name;
private $width;
public function __construct(string $name, int $width) {
$this->name = $name;
$this->width = $width;
}
public function name(): string {
return $this->name;
}
public function width(): int {
return $this->width;
}
public function setWidth(int $arg) {
$this->width = $arg;
}
}
function generate(): Named {
$widget = new Widget('top', 42);
return $widget;
}
$w = generate();
// можно ли заставить генерировать тут ошибку?
$w->setWidth(42);