Page 1 of 1

new to oop in PHP 4....

Posted: Tue Aug 19, 2008 3:42 pm
by jkashu
I am very new to oop in PHP.

I have a World class that has a User object as a member.

I declare it as:

Code: Select all

[b]var $mainUser;[/b]
...and instantiate it in the constructor:

Code: Select all

[b]$mainUser = new User();[/b]
In this function (from the World class) I am returning a member of the User class:

Code: Select all

    function data(){
    
        return $this->mainUser->getUserdata();
 
    }
But it tells me that Fatal error: Call to a member function getUserdata() on a non-object.. Do I have to declare $mainUser as an object or something??

Re: new to oop in PHP 4....

Posted: Tue Aug 19, 2008 3:45 pm
by jkashu
Nevermind...lol.....

I didn't say $this to instantiate it...

1. $this->mainUser = new User();