Podczas moich ćwiczeń PHP bawiłem się obiektówką i interfejsami. Stworzyłem taki kod.
<?php
/**
* Interface 'Documentable'
*/
interface Documentable
{
public function showDocument();
}
class DocumentToSend
{
public static $i = 0;
public $id;
public static $documents = [];
public function _construct(Documentable $document, $name = 'Document')
{
$this->id = $this->i;
$this->i++;
$this->documents[$this->id] = $document;
}
public function showId()
{
echo $this->id;
}
public static function setIterator($value = 0)
{
$this->i = $value;
}
}
/**
* Documents
*/
class HTMLDocument implements Documentable
{
public $document;
function __construct($text = '-')
{
$this->document = $text;
}
public function showDocument()
{
echo $this->document;
}
}
/**
* Code
*/
$document = new HTMLDocument('Wartosc tego dokumenta');
$end = new DocumentToSend($document, 'Jakas tam nazwa');
$end->showId();
?>
Po uruchomieniu funkcji showId() Na ekranie nie pojawiało się nic. Używam PHP w wersji 7.2.4. Wrzuciłem to do walidatora PHP i otrzymałem odpowiedź, że wszystko jest OK. Mimo że jest to kod ćwiczeniowy, to wskazówka jak rozwiązać problem może przydać mi się na przyszłość, a więc proszę o pomoc w rozwiązaniu problemu.