CKTIS / PHP
Ključna riječ insteadof
Rješava sukob metoda iz traitova odabirom jedne implementacije umjesto navedenih suparnica.
Verzija: PHP 8.4; repository runtime, production runtime not attested
Sintaksa
use Left, Right { Left::label insteadof Right; }Rješava sukob metoda iz traitova odabirom jedne implementacije umjesto navedenih suparnica. Isključenu metodu još je moguće uvesti pod drugim imenom pomoću as. Neriješen sukob metoda izaziva kobnu pogrešku.
trait Left {public function label(){return "L";}} trait Right {public function label(){return "R";}}
class Sign {use Left,Right {Left::label insteadof Right; Right::label as other;}}
$s=new Sign(); echo $s->label(),$s->other();
LR
Primjeri
<?php
trait Left {public function label(){return "L";}} trait Right {public function label(){return "R";}}
class Sign {use Left,Right {Left::label insteadof Right; Right::label as other;}}
$s=new Sign(); echo $s->label(),$s->other();
Rezultat
LR