Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class foo
- {
- protected bar = array();
- getBar()
- {
- return &bar;
- }
- }
- class foo2
- {
- blip = new foo().getBar(); // i know this isn't php
- }
- <?php
- class foo {
- protected $bar;
- public function __construct()
- {
- $this->bar = array();
- }
- public function &getBar()
- {
- return $this->bar;
- }
- }
- class foo2 {
- var $barReference;
- var $fooInstance;
- public function __construct()
- {
- $this->fooInstance = new foo();
- $this->barReference = &$this->fooInstance->getBar();
- }
- }
- $testObj = new foo2();
- $testObj->barReference[] = 'apple';
- $testObj->barReference[] = 'peanut';
- ?>
- <h1>Reference</h1>
- <pre><?php print_r($testObj->barReference) ?></pre>
- <h1>Object</h1>
- <pre><?php print_r($testObj->fooInstance) ?></pre>
Add Comment
Please, Sign In to add comment