Advertisement
Shishire

Incredibly Evil Code

Apr 15th, 2013
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.75 KB | None | 0 0
  1. <?php
  2.  
  3. class ImprintingChild
  4. {
  5.         protected $parent;
  6.         public function __construct()
  7.         {
  8.                 $backtrace = debug_backtrace(true);
  9.                 $this->parent = $backtrace[1]['object'];
  10.         }
  11. }
  12.  
  13. class UnsuspectingParent
  14. {
  15.         protected $child;
  16.  
  17.         public function createChild()
  18.         {
  19.                 $this->child = new ImprintingChild();
  20.         }
  21.         public function getChild()
  22.         {
  23.                 return $this->child;
  24.         }
  25. }
  26.  
  27. $x = new UnsuspectingParent();
  28. $x->createChild();
  29. $y = $x->getChild();
  30. var_dump($y);
  31. /*
  32. Output:
  33.  
  34. object(ImprintingChild)#2 (1) {
  35.   ["parent":protected]=>
  36.   object(UnsuspectingParent)#1 (1) {
  37.     ["child":protected]=>
  38.     *RECURSION*
  39.   }
  40. }
  41. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement