Created
November 4, 2013 06:16
-
-
Save gusdecool/7298722 to your computer and use it in GitHub Desktop.
How singleton passing property to child
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Place | |
{ | |
/** | |
* @var string | |
*/ | |
private $key; | |
/** | |
* @var PlaceNearby | |
*/ | |
private $nearby | |
public function __construct($key) | |
{ | |
$this->key = $key; | |
$this->nearby = new PlaceNearby(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
Class PlaceNearby | |
{ | |
public function __construct() | |
{ | |
// do something here | |
} | |
public function execute() | |
{ | |
// How can i get my parent key (@_@) | |
$this->parent->key; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment