If I have class:
class_A{
use SomeTrait;
}
And
class_B extends class_A{
//
}
How to disable trait "SomeTrait" in class_B class ?
If I have class:
class_A{
use SomeTrait;
}
And
class_B extends class_A{
//
}
How to disable trait "SomeTrait" in class_B class ?
Why extending class in first place when using traits - if - *(let's say it's true) there are A LOTS of traits in Your code/project .. ?
class A {
use private_trait_holding_this,
private_trait_holding_just_that;
// .. properties, public methods...
}
class B {
use private_trait_holding_just_that;
// ... properties, public methods ....
}
Traits are very powerful things, and I often like to refer to them as bags. Just because of this below. Note that everything inside traits is private.
trait private_properties {
private $path;
private $file_;
private $pack_;
}
trait private_methods_uno
{
private function getFilePrivate()
{
if(is_file($this->path))
$this->file_ = file_get_contents($this->path);
}
}
trait private_methods_due
{
private function putFilePrivate()
{
if(!is_string($this->file_))
die('File probably doesn\'t exist ... ');
else
{
$this->pack_ = base64_encode($this->file_);
file_put_contents(("{$this->path}.bak"), $this->pack_, LOCK_EX);
$this->pack_ = null; $this->file_ = $this->pack_;
}
}
}
final class opcodeToString
{
use
private_properties,
private_methods_uno,
private_methods_due;
public function __construct($path)
{
$this->path = $path;
$this->getFilePrivate();
}
public function putFile()
{
$this->putFilePrivate();
}
}
$filepath = '/my/path/to/opcode.php';
$ots = new opcodeToString($filepath);
$ots->putFile();
extending is still valid.. no 5hit .. !?! You have opened my eyes.. ;) Typehinting, yes, not possible with traits, but.. in this question, is there any word about type-hinting in first place?