![]() |
How to call classes?
I have this setup:
class a class b extends a class c class d extends c I want class d to be able to call several functions in class b. What is the best way of doing this? |
either pass class b to class d by reference or just have class d create a class b within it.
|
I would pass it as a reference.
PHP Code:
PHP Code:
PHP Code:
PHP Code:
|
Quote:
PHP Code:
|
Yes you can, but I would not advise it.
Sometimes the classes you want to include(for example a DB class), you need to set that class up with some basic values, in this example(the db class) you need to connect and select a db before you can use it. And if you have it instanciated in the __construct, you need to pass all the DB values to that class. Not to mention, it will be harder for you to use it in another class. It's easier to pass it as a reference, because then you can set it up before you pass it, plus you can pass it to several different classes. I'm not saying that my solution is the best in your case, but generally, you want to do how I said. Not good to learn bad habbits, they're so hard to get rid of. |
| All times are GMT. The time now is 06:20 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0