Search Results

Search found 1 results on 1 pages for 'yvo'.

Page 1/1 | 1 

  • OOP beginner: classB extends classA. classA already object. method in classB needed.. etc.

    - by Yvo
    Hey guys, I'm learning myself to go from function based PHP coding to OOP. And this is the situation: ClassA holds many basic tool methods (functions). it's __construct makes a DB connection. ClassB holds specific methods based on a certain activity (extract widgets). ClassB extends ClassA because it uses some of the basic tools in there e.g. a database call. In a php file I create a $a_class = new ClassA object (thus a new DB connection). Now I need a method in ClassB. I do $b_class = new ClassB; and call a method, which uses a method from it's parent:: ClassA. In this example, i'm having ClassA 'used' twice. Onces as object, and onces via a parent:: call, so ClassA creates another DB connection (or not?). So what is the best setup for this basic classes parent, child (extend) situation? I only want to make one connection of course? I don't like to forward the object to ClassB like this $b_class = new ClassB($a_object); or is that the best way? Thanks for thinking with me, and helping :d

    Read the article

1