Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class ImprintingChild
- {
- protected $parent;
- public function __construct()
- {
- $backtrace = debug_backtrace(true);
- $this->parent = $backtrace[1]['object'];
- }
- }
- class UnsuspectingParent
- {
- protected $child;
- public function createChild()
- {
- $this->child = new ImprintingChild();
- }
- public function getChild()
- {
- return $this->child;
- }
- }
- $x = new UnsuspectingParent();
- $x->createChild();
- $y = $x->getChild();
- var_dump($y);
- /*
- Output:
- object(ImprintingChild)#2 (1) {
- ["parent":protected]=>
- object(UnsuspectingParent)#1 (1) {
- ["child":protected]=>
- *RECURSION*
- }
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement