Skip to content

Error when compiling: Declaration of X must be compatible with Y

I’m new to Magento and working on upgrading an existing project to 2.4.3. When running php -dmemory_limit=5G bin/magento setup:di:compile I’m encountering an error:

Fatal error: Declaration of XRecurringServiceModelExportMetadataProvider::getHeaders(MagentoFrameworkViewElementUiComponentInterface $component) must be compatible with MagentoUiModelExportMetadataProvider::getHeaders(MagentoFrameworkViewElementUiComponentInterface $component): array in /code/X/RecurringService/Model/Export/MetadataProvider.php on line 82

That points to the following:

/**
 * Retrieve Headers row array for Export
 *
 * @param UiComponentInterface $component
 * @return string[]
 */
public function getHeaders(UiComponentInterface $component)
{
    return array(
        'Next Delivery Date',
        'Service?',
        'Diaper#',
        'Wipes',
        'Doublers',
        'Name',
        'Address 1',
        'Address 2',
        'Exchange Notes',
        'Old #s',
        'Action Date',
        'Action Req',
        'Driver Date',
        'Driver Action',
        'Driver',
        'Status'
    );
}

I’m guessing this is the result of something changing in the new version, but can’t seem to find any explanation or docs referencing it.