Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Try with Traits
- trait HelpManagerTrait {
- protected $entries;
- public function __construct() {
- $this->entries = array();
- }
- # DO NOT CALL
- protected function _addEntry($entry) {
- $this->entries[] = $entry;
- }
- public function printHelp() {
- print_r($this->entries);
- }
- }
- class HelpManager {
- use HelpManagerTrait;
- }
- class XYZ {
- protected $helpMan;
- public function __construct() {
- $this->helpMan = new HelpManager();
- }
- public function getHelpMan() {
- return $this->helpMan;
- }
- public function add($entry) {
- $test = $this->helpMan;
- $test = (HelpManagerTrait)$test;
- $test->_addEntry($entry);
- }
- }
- $xyz = new XYZ();
- $xyz->add('test');
- $xyz->getHelpMan()->printHelp();
- $xyz->getHelpMan()->_addEntry('illegal');
- $xyz->getHelpMan()->printHelp();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement