Intermittent PHP Abstract Class Error Intermittent PHP Abstract Class Error php php

Intermittent PHP Abstract Class Error


I think you've run into this opcache bug. This isn't exactly the same situation but probably related.

After calling opcache_reset() function we encounter some weird errors. It happens randomly on servers (10 of 400 servers production)

Some letter a replaced by others, Class seems to be already declared.. etc

Example of errors triggered after opcache_reset():

  • PHP Fatal error: Class XXX contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (YYY::funczzz) in /dir/dir/x.php on line 20

The ticket is closed because the developers don't have enough information to reproduce it. If you could come up with the smallest reproducible case I recommend reporting it. Create a very small Slim app and then use JMeter or another tool to make many requests. Post your findings.

Meanwhile the only workaround might be to turn off opcache in php.ini:

opcache.enable=0

Of course this will drastically hurt performance. Until it's fixed you'll have to choose between performance or periodically restarting Apache.

If turning the cache off doesn't work then the only cause I could think of is an intermittent problem with the opcode compiler. Cached or not the compiled version must have an error in it. Opening a reproducible ticket with the PHP devs or debugging the PHP source yourself would be the only way forward if this is the cause.


I had the same problem using CodeIgniter and PHP 7.1.x.

I upgraded to PHP 7.2 and the problem no longer occurred.


If you develop on Windows, I would recommend that you DON'T use XAMPP or WAMPP, and try out a real development server using Linux on a VM.

Try installing Vagrant and Virtualbox, then head to puphpet.com, which can generate you a virtual machine configuration. Unzip the download, cd in to the folder, type vagrant up. Then just point your host at the VM. I'll bet once you have a real development environment that this error will go away. Your other option is Docker, but that has a bit of a learning curve.

The problem isn't your code (or your vendor code), but your platform.