CKTIS / PHP
Typ PHP parent
W typie metody klasy pochodnej parent oznacza jej bezpośrednią klasę bazową.
Wersja: PHP 8.4; repository runtime, production runtime not attested
Składnia
public function base(): parentW typie metody klasy pochodnej parent oznacza jej bezpośrednią klasę bazową. Zwracana wartość może być odrębnym egzemplarzem tej klasy albo jej podklasy. Nie ma wymogu zwracania bieżącego obiektu. Klasa bez rodzica nie może używać tego oznaczenia.
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]
Przykłady
<?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]);
Wynik
["Document",false]