CKTIS / PHP
Keyword insteadof
Resolve a conflict between imported trait methods by selecting one implementation and excluding the named competitors for that method.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
use Left, Right { Left::label insteadof Right; }Resolve a conflict between imported trait methods by selecting one implementation and excluding the named competitors for that method. The excluded method can still be imported under an alias with as. An unresolved conflict between trait methods causes a fatal error.
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
Examples
<?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();
Result
LR