Shopware: $kernelClass must be string

How to fix an apparent bug after upgrading to Shopware 6.4.15.x.

1739 views

Edited: 2022-10-29 09:27

Compile Error: Type of Shopware\Production\HttpKernel::$kernelClass must be string (as in class Shopware\Core\HttpKernel)

This problem seem to happen because of a missing type declaration on line 5 in src/HttpKernel.php, there is also an official patch to fix it. E.g.:

<?php declare(strict_types=1);

namespace Shopware\Production;

class HttpKernel extends \Shopware\Core\HttpKernel
{
    protected static $kernelClass = Kernel::class;
}

To fix it, simply add the string type declaration in front of $kernelClass. E.g:

1. To fix the problem from a terminal:

nano +5 /srv/shopware/src/HttpKernel.php

2. Add the missing string type:

protected static string $kernelClass = Kernel::class;

Mismatch in types

The problem prevents you from updating Shopware, but requires only this minor edit to be fixed. It can happen, for example, after upgrading from Shopware 6.4.14.0 to 6.4.15.0 or even 6.4.15.1.

Please note, there are two files that named the same, but placed in different locations – one extending the other, which causes a mismatch with the declared type; so, let us say your Shopware root is /srv/shopware/, the file you need to edit is located here:

/srv/shopware/src/HttpKernel.php

This extends the class in core at:

/srv/shopware/vendor/shopware/core/HttpKernel.php

Tell us what you think:

Sebastian

Or simply add the string definition to your overwritten HttpKernel Class

protected static string $kernelClass = Kernel::class;

derf

Thank you so much! Faced this error today and found your solution. Now it works perfectly fine.

Robert

Many thanks, I also encountered this problem today and was able to solve it within minutes with your guide/solution! \m/,

  1. How to debug issues caused by corrupted custom fields in Shopware 6.
  2. Sometimes we may to manually clear cached Shopware files to fix namespace issues.
  3. How to obtain the currently selected API language from Shopware vue components.
  4. How to access file system paths from storefront twig files in Shopware.
  5. How to get or change the currently selected sales channel in an Shopware sw-sales-channel-switch component.

More in: Shopware