[PHP Dynamic Call method] provides a parameter solution
Source: Internet
Author: User
[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. ------- [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.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.