Title: TIP: Plugin development using PHP classes or the &#8220;Cannot redeclare class&#8221;.
Last modified: August 19, 2016

---

# TIP: Plugin development using PHP classes or the “Cannot redeclare class”.

 *  [dzenkovich](https://wordpress.org/support/users/dzenkovich/)
 * (@dzenkovich)
 * [17 years, 4 months ago](https://wordpress.org/support/topic/tip-plugin-development-using-php-classes-or-the-cannot-redeclare-class/)
 * Hi guys, thought this might be worth of sharing:
 * There is a weird problem in WP – the “Cannot redeclare class” plugin activation
   fatall error, and as in the past, looks like this is related to WP’s hooks into/
   admin side for missing files at the process of initializiation of the plugin 
   or something.
 * Whatever, point is – I’ve been struggling with this for couple of hours and the
   only solution (that is simple and powerfull enough) I’ve found – is to avoid 
   the classes in the main plugin file!
 * So this stands for:
    1. Use a stupid simple initiation file (the first file WP
   will load from you plugin directory) 2. Move all of you classes into other files(
   aka oldschool /includes) 3. Place a retarded check as: `if(class_exists('MyMainClass'))`
   4. Code include of the class file and it’s initialization only if check fails(
   yep, class is not here yet – we go).

The topic ‘TIP: Plugin development using PHP classes or the “Cannot redeclare class”.’
is closed to new replies.

## Tags

 * [plugin-development](https://wordpress.org/support/topic-tag/plugin-development/)

 * 0 replies
 * 1 participant
 * Last reply from: [dzenkovich](https://wordpress.org/support/users/dzenkovich/)
 * Last activity: [17 years, 4 months ago](https://wordpress.org/support/topic/tip-plugin-development-using-php-classes-or-the-cannot-redeclare-class/)
 * Status: not a support question

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
