Call Function in Separate File

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
blodder24
Forum Newbie
Posts: 7
Joined: Wed Nov 26, 2008 4:18 pm

Call Function in Separate File

Post by blodder24 »

I have a function, merge(), in admin.php which is defined by: class admin extends catalog. (catalog is a file with more functions) When I try to call this function from index.php by using $admin->merge I get the error: Call to a member function merge() on a non-object.

Any idea what's going wrong?

Thanks
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: Call Function in Separate File

Post by Mark Baker »

have you instantiated an object of class admin?
blodder24
Forum Newbie
Posts: 7
Joined: Wed Nov 26, 2008 4:18 pm

Re: Call Function in Separate File

Post by blodder24 »

Thanks! That solved one problem, but created another.
How do you initiate: $this->core->db->run() inside the function merge()? I'm getting the same error when I try to run this function.
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: Call Function in Separate File

Post by Mark Baker »

blodder24 wrote:How do you initiate: $this->core->db->run() inside the function merge()? I'm getting the same error when I try to run this function.
Assuming you've instantiated an object of your database class, you pass that object as a parameter into the call to instantiate your admin class, and stick it in one of your admin class attributes.
That way, it's available to all the methods in your admin class
blodder24
Forum Newbie
Posts: 7
Joined: Wed Nov 26, 2008 4:18 pm

Re: Call Function in Separate File

Post by blodder24 »

Thanks for your help!
Post Reply