Required class could not be loaded properly for reflection. - when migrating to production server

Hi,

when migrating an application to the production server I am getting the following error:

Required class "Bit\GkwIncidentSite\Bit\GkwIncidentSite\Command\GkwCommandController" could not be loaded properly for reflection`

Although the controllers class file is in the proper location:

/home/ ... /public_html/Packages/Sites/Bit.GkwIncidentSite/Classes/Bit/GkwIncidentSite/Command/GkwCommandController.php

composer.json:

{
  "name": "bit/gkwincidentsite",
  "type": "neos-site",
  "description": "Add description here",
  "require": {
    "neos/neos": "*",
    "neos/nodetypes": "~3.0",
    "neos/swiftmailer": "~6.0",
    "phpoffice/phpexcel": "^1.8",
    "mobiledetect/mobiledetectlib": "^2.8",
    "flowpack/neos-frontendlogin": "~3.0",
    "moc/notfound": "^3.0"
  },
  "suggest": {
    "neos/neos-seo": "*"
  },
  "autoload": {
    "psr-4": {
      "Bit\\GkwIncidentSite\\": "Classes"
    }
  }
}

I tried flushing all caches both via ./flow and manually to no avail.

Has anyone a hint on that?

Best
Robert.

Hi @robertobottoni,

that error has usually to do with some mistake with the code inside the required class.
For example if you mistype the namespace of the class or similar error.

As I can see Flow tries to load Bit\GkwIncidentSite\Bit\GkwIncidentSite\Command\GkwCommandController (note the double"Bit\GkwIncidentSite" ), but usually should be something like

Bit\GkwIncidentSite\Command\GkwCommandController` (single package declaration)

That could be a starting point to track down your issue.

Nicola

Hi @ilCerchiari,

thanks for your reply. I already noticed the doubled Vendor and Package path segments but have no clue why this happens. I have the same packages and configuration running properly on the dev system. Maybe something from the environment is causing it?

Best
Robert.

@robertobottoni unfortunately I have no clues what can cause that (no hints on the platforms you are deploying to) but mostly sure is that issue that causes your problem.

Hope it can help,

Nicola

I know this is not a recent post, but it might help someone out there:

I ran into a similar problem. I’m almost positively sure that the reason is a change from psr-0 to psr-4 autoloading. When I moved my class folders from
flow/Packages/Sites/Vendor.Package/Classes/Vendor/Package/Controller
to
flow/Packages/Sites/Vendor.Package/Classes/Controller
Everything worked again.

My story was that the installation had two site packages, Neos.Demo and a custom site package.
To update the custom site package, I changed settings here and there to reflect the Neos.Demo settings. At that point I didn’t know the difference about psr-0 and psr-4, but I changed this in the composer.json file as well. Maybe that was a part of the reason why it now failed.
So everything worked okay until I removed the Neos.Demo package. Then bam! I got this error.

https://www.sitepoint.com/battle-autoloaders-psr-0-vs-psr-4/

1 Like