Home  >  Article  >  Backend Development  >  Problems with variable scope in PHP implementation of plug-in mechanism

Problems with variable scope in PHP implementation of plug-in mechanism

WBOY
WBOYOriginal
2016-09-05 08:59:59849browse

1. I want to implement the plug-in mechanism in my blog. The problem I am facing now is to add hooks on many nodes of the program and then execute the calls on the hooks.

2. But I have a question: how to pass data to the call on the hook? Pass it directly with parameters? I think this is too rigid. Is there a flexible way? Or use global?

3. I have been struggling with this problem for a long time, please answer ^-^

Reply content:

1. I want to implement the plug-in mechanism in my blog. The problem I am facing now is to add hooks to many nodes of the program and then execute the calls on the hooks.

2. But I have a question: how to pass data to the call on the hook? Pass it directly with parameters? I think this is too rigid. Is there a flexible way? Or use global?

3. I have been struggling with this problem for a long time, please answer ^-^

It is both rigid and standardized. Making a hook has relatively clear parameters, which is better for program maintainability and scalability. Furthermore, your incoming parameters are variable, and you can achieve whatever you want through an array encapsulation. Parameter form.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn