[thelist] basic OO php question

Rick den Haan rick.denhaan at gmail.com
Wed Apr 18 03:31:25 CDT 2007


I feel like a noob asking this, but I've never needed to do this before.

If I call a class (Y) from within another class (X), is it possible to
access properties of X from within Y without have Y extend X?

If that's vague, allow me to give a barebones example of what I want:

class X
    var $foo = "bar";

    function X()
        $y = new Y();

class Y
    function Y()
        echo parent::$foo;
        // Doesn't work, because Y does not extend X, but I want this to
output "bar"

I'd pass $foo along with the call, but in the practical use I have in mind
X() has a lot more properties. I could potentially pass $this along, but I
doubt if that's a very recommendable practice.

Any thoughts?


More information about the thelist mailing list