[UPHPU] Accessing a Parent Object's Other Variables
Kirk Ouimet
kirk at kirkouimet.com
Mon Jun 22 12:57:31 MDT 2009
Hi List,
I need to be able to access a other variables in a parent class from an
object inside the parent class. Here's what I've cooked up, but it throws a
*RECURSION* warning:
<?php
Class A {
var $msg = 'Why hello there my old friend';
var $b;
function __construct() {
$this->b = new B($this);
}
}
Class B {
var $a;
function __construct($a) {
$this->a = $a;
}
}
$a = new A();
$b = $a->b;
echo $b->a->msg;
// Output: Why hello there my old friend
print_r($a);
/* Output:
(
[msg] => Why hello there my old friend
[b] => B Object
(
[a] => A Object
*RECURSION*
)
)
*/
?>
Is the *RECURSION* warning bad coding on my part? What's a best practice
here?
Thanks!
Kirk Ouimet
<mailto:kirk at kirkouimet.com> kirk at kirkouimet.com
Cell: (801) 310-1421
More information about the UPHPU
mailing list