Search code examples
phpautoloadopcode-cache

Do PHP opcode cache work with __autoload?


Sorry if this is basic, I am trying to learn as much as I can about OO in PHP and I am slowly learning how to use it (very limited).

So I am wanting to know if __autoload() has any affect on PHP opcode cache's?


Solution

  • (Disclaimer : I only know APC)

    What an opcode cache do is :

    • when a file is included/required, it take the full path to that file
    • check if the opcodes corresponding to that file are already in RAM (in opcode cache)
      • if yes, return those opcode so they are executed
      • if no, load the file and compile it to opcodes ; and store opcodes in cache.

    The important point, here, is the entry point : the full path to the file.


    What autoloading generally do is :

    • get the name of a class
    • transform it to the name of a file
    • include/require that file

    So, the informations that are relevant for the opcode cache (full path to the file, and the fact that it is included/required) are still here.

    In consequence, autoload shouldn't bring any trouble with op code caching.

    (And, when using APC, it doesn't, as far as I can tell)