How To Fix Class Not Found Fatal Error

Fix with CodePinch instantly >

Symptoms

Either a blank website page or a fatal error as shown in the example below:

Class ‘ZipArchive’ not found
Class ‘WP_Role’ not found
Class ‘DOMDocument’ not found

Cause

The only cause for this fatal error is that requested class does not exist in the scope of the executable code. In other words – your website simply does not know about the requested class. It is one of the most common errors when a website has multiple plugins installed that depend on each other or website server is missing one of the required PHP libraries like ZipArchive or Memcache.

Requirements

In order to fix this fatal error, you should have good knowledge in PHP to debug the source code. Additionally you have to be aware of different PHP libraries that are available for PHP and how to activate them whenever is required and possible.

Read Me First

This error can be automatically fixed with CodePinch. Download CodePinch on your website and within hours we will be able to provide you with solution.

Resolution

The ideal way to resolve this error is to find out where missing class is declared. Pay attention to the namespaces because sometimes developers mistakenly requesting a class from the wrong namespace.

When missing class is declared in the PHP core (e.g. DOMDocument, ZipArchive, DirectoryIterator) then you would have to check in the official php.net what PHP version and library you need to have to support this class.

When missing class is declared in one of the files of your application, then you would have to make sure that class exist before calling it. The example below shows how to fix very common fatal error “Class ‘WP_Widget_Recent_Posts’ not found”. This solution ensures that your website get executed even when the class WP_Widget_Recent_Posts does not exist anymore in the website’s codebase.

@@ -11,9 +11,9 @@
- $widget = new WP_Widget_Recent_Posts();
+ $widget = (class_exists('WP_Widget_Recent_Posts') ? new WP_Widget_Recent_Posts() : null);

Note! This solution should be considered only as emergency/temporary. You still have to consult with professional software developer to find out the root cause of the fatal error and, if necessary, refactor the code-base.

Fix WordPress PHP errors instantly with CodePinch!

Get Started
Thank You! Message Submitted Successfully!