componere icon indicating copy to clipboard operation
componere copied to clipboard

PHP 7.4, Fatal error: subclass has colliding constructor definitions coming from traits

Open ASchmidt1 opened this issue 4 years ago • 0 comments

Sorry, 3.1.2 still not compatible with PHP 7.4, when extending a final class with a trait. Works with Componere under 7.3, and (if class is not final) also works with native 7.4.

Output under 7.3:

PHP 7.3.23, Componere 3.1.2 MySub1, extended MyClass1 via Trait! MySub2, extended MyClass2 via Trait!

Output under 7.4:

PHP 7.4.11, Componere 3.1.2 MySub1, extended MyClass1 via Trait! Fatal error: MySub2 has colliding constructor definitions coming from traits on line 35

Minimal sample code:

`<?php declare(strict_types=1);

error_reporting( E_ALL ); ini_set( 'display_errors', '1' ); ini_set( 'html_errors', '1' ); echo date(DATE_RFC2822), ' PHP ',phpversion(), ', Componere ', phpversion( 'Componere' ), "
\r\n";

/* Trait to override constructor */ trait MyTrait { public function __construct() { echo get_class(), ', extended ', parent::class, ' via Trait!', "
\r\n"; }
}

/* Use native PHP to extend class with trait */ class MyClass1 { public function __construct() { echo get_class(), "
\r\n"; } }

class MySub1 extends \MyClass1 { use \MyTrait; } // Success!

$myObj1 = new \MySub1();

/* Use Componere to extend final class with trait */ final class MyClass2 { public function __construct() { echo get_class(), "
\r\n"; } }

$myDef = new \Componere\Definition( 'MySub2', \MyClass2::class ); $myDef->addTrait( '\MyTrait' ); // PHP 7.4 = Fatal error: MySub2 has colliding constructor definitions coming from traits $myDef->register(); unset( $myDef ); // Clean-up global namespace.

$myObj2 = new \MySub2(); // PHP 7.3 = Success! ` comp312.zip

ASchmidt1 avatar Oct 15 '20 22:10 ASchmidt1