Baza znanjaIzpitno središče
SLSlovenščina
Izberi jezik13

CKTIS / PHP

Ključna beseda insteadof

Razreši spor med metodami traitov tako, da izbere eno izvedbo namesto naštetih tekmic.

Različica: PHP 8.4; repository runtime, production runtime not attested

Sintaksa

use Left, Right { Left::label insteadof Right; }

Razreši spor med metodami traitov tako, da izbere eno izvedbo namesto naštetih tekmic. Izločeno metodo je še vedno mogoče uvoziti pod drugim imenom z as. Nerešen spor metod povzroči usodno napako.

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

Primeri

<?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

Viri