How to use a custom function file to rewrite the function files in another php post, which was last edited by qq37431300 at 2014-01-1610: 28: 54 in order not to modify the program's system file, this prevents files modified after the upgrade from being overwritten during the upgrade. Therefore, you want to create a new custom function library file: extention. php & nbsp;, & nbsp; include extentio during system running how to rewrite functions in another php with a custom function file
This post was last edited by qq37431300 at 10:28:54
In order not to modify the system file of the program and prevent files modified after the upgrade from being overwritten during the upgrade, you want to create a new custom function library file: extention. php: include this extention when the system is running. php. you can modify the system functions in php in extention. write your own functions in php.
For example
There are three php files
A. php system library file cannot be modified
Extention. php custom function library file, add and modify at will
Result. php calls the method file in the function library
A. php
Function show ()
{
$ Str = 'This is ';
Return $ str;
}
Extention. php I also wrote a show () function in it. I want to modify the show () method in a. php.
Function show ()
{
$ Str = 'This is my extention ';
Return $ str;
}
Result. php includes the above two php files and calls the show () method.
Include 'A. php ';
Include 'extention. php ';
$ Result = show ();
Echo $ result;
In this way, the Cannot redeclare error will be reported when you access result. php.
I found a document on the Internet and said I could use a namespace, but it seems that the effect is not what I want.
I don't want to touch the system's function library file, such as. php; only modify my extention. php user-defined function library file, so that. modify the functions in php. I don't know if I can do it?
Share: More
------ Solution --------------------
Inherit the system function library and write the same function name
------ Solution --------------------
A. php
Function show ()
{
$ Str = 'This is ';
Return $ str;
}
Extention. php I also wrote a show () function in it. I want to modify the show () method in a. php.
Class extention extends {
Function show ()
{
$ Str = 'This is my extention ';
Return $ str;
}
}
------ Solution --------------------
Two options:
1. namespace
2. directly modify the target function
------ Solution --------------------
Not all of your a. php files cannot be changed.
We recommend that you use the PHP namespace to call functions with the same name.
For example.
Test/B. php
namespace testb;
function test(){
return 'b.php';
}
Test/c. php
namespace testc;
function test(){
return 'c.php';
}
Test/a. php to call
include('b.php');
include('c.php');
echo \testb\test();
echo \testc\test();
------ Solution --------------------
No!
Your idea is that php cannot be implemented because php does not support heavy load.
Although the namespace mentioned above can alleviate this conflict
But it is not suitable for application scenarios, because you do not intend to modify the original system code, and function calls are initiated by the original system.