a class inside a class

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
johnrau_
Forum Newbie
Posts: 1
Joined: Sun Jun 06, 2004 6:21 pm

a class inside a class

Post by johnrau_ »

hi, i've been trying to use the functionality of one class inside another:

should the following code work in theory?

Code: Select all

class out {
    var $output = "yay";
    function put() {
        echo $this->$output;
    }
}

class test {
    function testme() {
        global $out;
        $out->put();
    }
}

$out = new out;
$test = new test;

$test->testme();
the above should output yay, right?

thanks
j
User avatar
launchcode
Forum Contributor
Posts: 401
Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:

Post by launchcode »

It will if you fix you echo statement :)

Code: Select all

echo $this->output;
Note the lack of $
Post Reply