Heya,
so I've worked on PHP for a while, but only recently started to learn OOP. I've been following the tutorials
here on killerphp, and started implementing OOP into a private project of mine. However, I've recently
struck a bit of a problem which I assume is very easy to those of you that know OOP.
So, the case:
I've been creating a class that I've been using to connect to my DB.
The connectdb -class contains two functions, one construct and one function
that actually connects to the DB. All variables (with host information for the DB) are declared private inside the class.
This have been working fine, but when I tried to take this a bit further I got stuck: I'm creating a new class (popup)
that's meant to get data from the DB based on user input. What I want to do is make the popup class use methods
from the connectdb -class, i.e connect to the DB. I tried something simple as connectdb::do_connect() inside
a popup method, but this obviously didn't work as the connectdb -class hadn't been constructed. I also tried
calling the construct method of the connectdb -class, but this only didn't work but also looked weird/wrong to me.
Thus I'm stuck with making two handlers, one to create the connectdb -class and one for the popup -class. Is this really
necessary?
I'm not providing the code in this post, as I assume someone with experience knows this in the back of their heads
Thanks for any replies.