"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;