Advertisement
Guest User

Untitled

a guest
Jul 9th, 2015
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.58 KB | None | 0 0
  1. <?php
  2.  
  3. class A {
  4.     public static $object;
  5.     public function createb()
  6.     { return new B(self::$object); }
  7. }
  8. class B {
  9.     public $object;
  10.     public function __construct($object)
  11.     { $this->object = $object; }
  12. }
  13.  
  14. $a = new A;
  15. $a::$object = (object) ['val' => 1];
  16. $b1 = $a->createb();
  17. $a::$object = (object) ['val' => 2];
  18. $b2 = $a->createb();
  19.  
  20. print_r($b1);
  21. print_r($b2);
  22.  
  23. /* Output:
  24. B Object
  25. (
  26.     [object] => stdClass Object
  27.         (
  28.             [val] => 1
  29.         )
  30.  
  31. )
  32. B Object
  33. (
  34.     [object] => stdClass Object
  35.         (
  36.             [val] => 2
  37.         )
  38.  
  39. )
  40. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement