Title: Cannot redeclare __construct bug
Last modified: September 11, 2020

---

# Cannot redeclare __construct bug

 *  Resolved [hamarkhis](https://wordpress.org/support/users/hamarkhis/)
 * (@hamarkhis)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/cannot-redeclare-__construct-bug/)
 * Hello,
 * I tested this little code on standard PHP7.4 without any error e.g. on [http://www.writephponline.com](http://www.writephponline.com)
 *     ```
       function test_class() {
       	return new class {
       		public $value;
   
       		function __construct() {
       			$this->value = 'my value';
       		}
   
       		public function some_class() {
       			return new class {
       				public $internal;
   
       				function __construct() {
       					$this->internal = "internal";
       				}
       			};
       		}
   
       	};
       }
   
       echo test_class()->some_class()->internal;
       ```
   
 * When going on with code snippets, I have a __construct redeclare bug… tested 
   on WordPress 5.5.1 fresh site.
 * So I believe there is something wrong with the plugin somewhere.
 * Any help is appreciated.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/cannot-redeclare-__construct-bug/#post-13395557)
 * It looks like this is due to the duplicate function detector not understanding
   how to work with subclasses.
 * I’ll see what I can do to fix it – thanks for reporting!
 *  Plugin Author [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/cannot-redeclare-__construct-bug/#post-13733079)
 * Thanks once again for reporting this – apologies for taking so long to sort out
   a solution.
 * It turns out that the validator had no idea how to handle anonymous classes. 
   Anonymous functions are super common, but I haven’t seen anonymous classes nearly
   as much (if at all?) so it didn’t occur to me to add support for them when I 
   was writing it.
 * A fix for this will be included in the next release.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Cannot redeclare __construct bug’ is closed to new replies.

 * ![](https://ps.w.org/code-snippets/assets/icon.svg?rev=2148878)
 * [Code Snippets](https://wordpress.org/plugins/code-snippets/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/code-snippets/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/code-snippets/)
 * [Active Topics](https://wordpress.org/support/plugin/code-snippets/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/code-snippets/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/code-snippets/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * Last activity: [5 years, 6 months ago](https://wordpress.org/support/topic/cannot-redeclare-__construct-bug/#post-13733079)
 * Status: resolved