• Resolved hamarkhis

    (@hamarkhis)


    Hello,

    I tested this little code on standard PHP7.4 without any error e.g. on 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

    (@bungeshea)

    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

    (@bungeshea)

    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.