CKTIS / PHP
Palavra-chave insteadof
Resolve um conflito de métodos de traits escolhendo uma implementação em vez das concorrentes indicadas.
Versão: PHP 8.4; repository runtime, production runtime not attested
Sintaxe
use Left, Right { Left::label insteadof Right; }Resolve um conflito de métodos de traits escolhendo uma implementação em vez das concorrentes indicadas. O método excluído ainda pode ser importado com um alias por as. Um conflito por resolver gera um erro fatal.
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
Exemplos
<?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();
Resultado
LR