Znalostná bázaCentrum skúšok
SKSlovenčina
Vybrať jazyk13

CKTIS / PHP

Typ PHP parent

V odvodenej triede označuje typ parent jej priamu základnú triedu.

Verzia: PHP 8.4; repository runtime, production runtime not attested

Syntax

public function base(): parent

V odvodenej triede označuje typ parent jej priamu základnú triedu. Metóda môže vrátiť samostatnú inštanciu tejto triedy alebo podtriedy. Nemusí vrátiť aktuálny objekt. Trieda bez rodiča tento typ použiť nemôže.

class Document {}
class Invoice extends Document { public function base(): parent { return new Document(); } }
$invoice = new Invoice();
echo json_encode([get_class($invoice->base()), $invoice->base() instanceof Invoice]);
["Document",false]

Príklady

<?php
class Document {}
class Invoice extends Document { public function base(): parent { return new Document(); } }
$invoice = new Invoice();
echo json_encode([get_class($invoice->base()), $invoice->base() instanceof Invoice]);

Výsledok

["Document",false]

Zdroje