<?php
trait TraitA {
public function methodA() {
var_dump(__METHOD__);
}
public function methodB() {
var_dump(__METHOD__);
}
}
class ClassA {
use TraitA {
methodA as private traitMethodA;
methodB as private traitMethodB;
}
public function methodA() {
var_dump(__METHOD__);
$this->traitMethodA();
}
}
$o = new ClassA();
$o->methodA();
$o->methodB();
$o->traitMethodB();
string(15) "ClassA::methodA"
string(15) "TraitA::methodA"
string(15) "TraitA::methodB"
Fatal error: Uncaught Error: Call to private method ClassA::traitMethodB() from global scope in /in/EmNhJ:27
Stack trace:
#0 {main}
thrown in /in/EmNhJ on line 27
Process exited with code 255.
string(15) "ClassA::methodA"
string(15) "TraitA::methodA"
string(15) "TraitA::methodB"
Fatal error: Uncaught Error: Call to private method ClassA::traitMethodB() from context '' in /in/EmNhJ:27
Stack trace:
#0 {main}
thrown in /in/EmNhJ on line 27
Process exited with code 255.
string(15) "ClassA::methodA"
string(15) "TraitA::methodA"
string(15) "TraitA::methodB"
Fatal error: Call to private method ClassA::traitMethodB() from context '' in /in/EmNhJ on line 27
Process exited with code 255.