Execute PHP's "require" or "include" only when necessary.
29 Jun 2011
As I learned the existence of __halt_compiler, I tried to compact huge data into rarely used PHP file.
And I use the file in this way:
if (...statement of init matched...) {
require('init.dat'); // It is *.dat since it contains binary data for __halt_complier
}
However, because require or include will include the file no matter the code is actually executed or not, the large amount of data will be processed.
After a few days' thinking, I finally came out with this idea which will execute require only when necessary:
if (...statement of init matched...) {
eval("require('init.dat');");
}
Note that eval('?>'.file_get_contents('init.dat')); will NOT do because of the existence of __halt_compiler