[PHP Dynamic Call method] I have a VO class with parameters. ColumnVoextendsModel I want to call the Vo method in the Model. & Nbsp; But: newColumnVo ($ db), here we need to input a heavyweight $ db. but the method in my Vo is not applied to $ db. ------------------------------------------ In the Model, you need to implement the [PHP Dynamic Call method] with parameters
I have a VO class.
ColumnVo extends Model
I want to call the Vo method in the Model.
But: new ColumnVo ($ db), here we need to input a heavyweight $ db.
However, the method in my Vo should not be applied to $ db.
------------------------------------------
To implement this function in the Model: $ this-> Vo method (method parameter) what should I do?
Because $ this has already pointed to ColumnVo, and $ db already exists during ColumnVo initialization.
If reflection is used, perform the following steps:
1. new ColumnVo
2. call the new Vo method.
In this case, resources are wasted. There is also no way to call other initialized resources of the current $ this.
------ Solution --------------------
Singleton mode
------ Solution --------------------
It takes a long time to understand that you want some sub-classes not to inherit a certain attribute or method of the parent class?
Think of a solution in the constructor of the parent class.
------ Solution --------------------
As the boss said, the singleton mode does not allow you to transmit objects. Call a static method as needed.
In addition, it is sufficient to call a method dynamically with call_user_func_array ().
------ Solution --------------------
I think you're confused.
ColumnVo extends Model
You instantiate columnVo instead of Model.
The so-called method of calling columnVo in the Model
The new method of the subclass is called in the inherited parent class method.