grikdotnet

passing a DI container with a trait

Apr 5th, 2016
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.30 KB | None | 0 0
  1. <?php
  2.  
  3. trait A {
  4.  
  5.     protected static $container = 1;
  6.     public static function setContainer($c){
  7.         self::$container = $c;
  8.     }
  9. }
  10.  
  11. class C{
  12.     use A;
  13.  
  14.     public function foo(){
  15.         var_dump(self::$container);
  16.     }
  17. }
  18.  
  19.  
  20. A::setContainer(2);
  21.  
  22. $c = new C();
  23.  
  24. $c->foo();
Advertisement
Add Comment
Please, Sign In to add comment