Search code examples
phpclassapcfatal-error

APC Fatal: Missing class information


According to this PHP bug report, the error message is caused by nesting a class in an if statement and having it declared statically as well.

I have a class declared in only one place, but I've protected it with an if:

if (!class_exists('myClass', false)) {
    class myClass{

(Trying to do something similar to the C++ pre-processor directives / conditional inclusions.)

This was to prevent failing from the possibility of multiple coders including it improperly (require instead of require_once). My only other alternative at this point is to comment out the if's and search the application for includes and just make them all "require_once's".

So, has anyone else ran into this error, and is there a way to get around besides changing all the requires to require_once? (This software is maintained by multiple coders, so I'd like to keep it from failing.)

  • This error only occurs on occasion (randomly) and when it does, I have to add / remove a space from the class file and re-save to fix the error.

On a side note, the main reason we installed APC was for file upload progress support for IE 9 and under. So if we can keep just those parts enabled we could disable whatever feature causes this. (Not sure if that's possible.)

Update: Resaving the file apparently doesn't have an effect. It looks like it has a sort of "timeout". When the error occurs, I have to simply wait a while for it to go away.


Solution

  • It seems that this may be caused by autoloading classes as well as including class dependencies in the classes themselves.

    Before we had upgraded to PHP 5.3, we didn't have the option of using PHP's autoloading functionality. We therefore had to include the class dependencies in the class file. For example:

    <?php
    require "parent_class.php";
    
    if (!class_exists('this_class')) {
        class this_class extends parent_class {
    

    When we upgraded to PHP 5.3, we implemented the class autoloading functionality. This is probably how the "static" and "dynamic" class declarations (according to the PHP Bug in the question) are occuring. - Statically being declared in the actual class file and dynamically being declared in the autoloader.

    I went through and removed all of the includes / requires for class dependencies. This has solved the problem.