What is a data injection variable? What is its usage scenario?

Source: Internet
Author: User
"How does PHP introduce the concept of data injection variables in Java?" 』
http://segmentfault.com/q/10100000001 ...

Do you have any information about this concept and its usage?

Reply content:

"How does PHP introduce the concept of data injection variables in Java?" 』
http://segmentfault.com/q/10100000001 ...

Do you have any information about this concept and its usage?

It's not as good as adding a reference variable to a variable called an injection, as I answered in that question. And this scenario is where everything needs to be referenced in a singleton pattern, such as when you called model in a controller, you might want to write

Class Controller_test extends controller{public    function execute ()    {        $this->loadmodel (' user ') Fetch (...);    }}

This is called calling, no matter how you do the singleton pattern is called from outside of this object. But if you follow the method I mentioned in the previous answer __get , then this externally invoked object is injected into an internal property, and its benefits are obvious, and it's a lot less cumbersome and clearer, from a performance reduction of multiple invocation and function call consumption

Class Controller_test extends controller{public    function execute ()    {        $this->usermodel->fetch (... );    }}

Let me give you an example.
User:

ID | name | Age

This way, if there is a variable injection, initialize an object.

$user = new Userobj ();//At this time $user this instance does not load the name data echo $user->name;//call the Name property to inject, load the data

In fact, this userobj does not define the name attribute, but instead injects it into the
Add a field to user birthday

ID | name | Age | Birthday

That call, is already a direct call, do not need to modify the definition of Userobj

$user = new Userobj (); Echo $user->birthday;
  • 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.