"PHP Dynamic Call method" with parameters to solve the idea

Source: Internet
Author: User
"PHP Dynamic Call method" with parameters
I have a VO class.
Columnvo extends Model

I want the model to call Vo's method.

However: New Columnvo ($DB), here to pass in a heavyweight $db.
But my Vo method is not applied to the $db.
------------------------------------------
This function is implemented in model: What about $this->vo method (method parameter)?

Because the current $this has pointed to columnvo, and columnvo initialization, there are already $db.
If using reflection, it is not necessary to go through the following steps:
1.new Columnvo
2. Call the new Vo method.
In this case, the resources are wasted. And there is no way to invoke the other already initialized resources of the current $this.

------Solution--------------------
Single-Case mode
------Solution--------------------
I've seen it for a long time. Do you want some subclasses to inherit a property or method from the parent class?
It's better to think of something in the constructor of the parent class.
------Solution--------------------
As the boss said, the singleton mode can no longer allow you to transfer the object. Call a static method where you need it.
In addition, dynamic invocation of a method, with Call_user_func_array () enough
------Solution--------------------
I think you're messing things up.

Columnvo extends Model
You instantiate a columnvo, not a Model.
The so-called method of calling Columnvo in Model
is to call the subclass new method in the inherited parent class method
  • Contact Us

    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.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.