new to oop in PHP 4....

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
jkashu
Forum Commoner
Posts: 45
Joined: Tue Jan 30, 2007 12:00 pm

new to oop in PHP 4....

Post 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??
jkashu
Forum Commoner
Posts: 45
Joined: Tue Jan 30, 2007 12:00 pm

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

Post by jkashu »

Nevermind...lol.....

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

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