1

I'm working in Vtiger (MVC set up), The modules contain the MVC files. Modules extend other modules by extending the class of the other module. In the case I am looking at, the Quote extends the Inventory module. The outcome is a custom block inside the Quote, not a whole new "page".

I want that "block" which is really a whole module. So this should be simple, except that I ran into PHP "inheritance" issues. The class I need to extend is an extended class already.

My logic was: ( B gets C ) works! now A gets B stuff. This did not work.

The Parent Class Class Event extends Calendar (shows event details / "final page")

The exiting "working" class Class Event extends Inventory (creates new block)

I need these two classes to communicate, since Calendar already "talks" to Events, and Events talks to Inventory, the variables are unrelated, but I cannot get the Output to work, I assume because of class "inheritance"

So the direct question is: can an existing child class be extended?

  • Stack addresses this in few posts but I'm not able to "grasp" how this applies here since no variables are shared, there should not be any bad obj calls.

Here are my resources for learning to "connect" child classes:

I tried to explain my reference to the problem as it may not be php related but rather my understanding. Thank you in advance.

Community
  • 1
  • 1
zzipper72
  • 945
  • 2
  • 10
  • 24
  • Extending a class will actually create a new class that has access to the same methods and properties of the parent class. It is the child class getting new methods/properties, not the parent. It doesn't modify the parent class to add those methods. So if you have `class A` and two classes that extend A like `class B extends A` and `class C extends A` (which is what you are doing) then classes `B` and `C` only share the methods defined in `A`, not each other. You can change class `C` to extend `B` and it would have access to both parent classes. Example: http://codepad.viper-7.com/7gWtmj – Jonathan Kuhn Dec 01 '14 at 22:38
  • great example, thank you. I think this is the opposite though .. A and B already are used. B and C are the new pair. If I understand your explanation ( has access to the same methods and properties of the parent class) ... Can I simply make A to C, then when A calls B (like it normally would)... B would then have access to C through A ?? Mine: [A+(B]+C) ..did not work will ([A+B]+[A+C])work? I can not change the properties of A+B.. I can only connect C as an add on. Sorry if I'm complicating a simple thing. – zzipper72 Dec 01 '14 at 23:22
  • 1
    You could make a new class (C) and have it extend (B). Then A and B will have access to C. If you redefine (override) a method in C that exists in A or B, when A or B refer to `$this` it will be class C. Example: http://codepad.viper-7.com/kHTSCt There is now a method defined in A that C overwrites and another method defined in A that uses `$this` to access the previous overwritten method. This of course depends on how A and B try to access the methods defined in their parents and children (using $this instead of specifically `parent::method` or `child::method`). – Jonathan Kuhn Dec 01 '14 at 23:48
  • I understand, thank you. The problem for me lies in the existing code since I did extend B with C. I'll have to hunt for the conflict. Thanks for the clarification! Please answer with your first comment and I will mark as the correct answer as it explains the relationship of the properties between the order of classes. – zzipper72 Dec 01 '14 at 23:59

0 Answers0