Frustrating problem : [Nextcloud 28, Docker] Persistent "Cannot declare class ... already in use" error for custom app

Hello Nextcloud community,

I’m experiencing a persistent PHP Fatal error:

Cannot declare class ... because the name is already in use

This happens when trying to load or enable custom apps in my Nextcloud 28 environment.
The error prevents Nextcloud from fully loading and listing apps.

The specific error points to:

/var/www/html/custom_apps/animated_helloworld_app/lib/AppInfo/Application.php on line 13

This is confusing because I already deleted the local folder for animated_helloworld_app and even tried creating a completely new app (hello_andreas_app), but the error persists and still points back to the old animated_helloworld_app.


The Basics

  • Nextcloud Server version: 28.0.14.1
  • Operating system and version: Ubuntu 25.04
  • Web server and version: Apache (from Nextcloud Docker image)
  • Reverse proxy: None (Docker handles internal routing)
  • PHP version: 8.2 (from Nextcloud Docker image)
  • First time error seen? Yes (on this specific setup)
  • When did it start? Immediately after creating the first custom app (my_helloworld_app)
  • Installation method: Docker Compose
  • Cloudflare / mod_security / similar? No

Summary of the issue

I am encountering a persistent PHP Fatal error:

Cannot declare class ... because the name is already in use

The error points to a class within an app that I have already tried to remove or replace.
As a result, Nextcloud cannot fully load or list apps.


Steps to reproduce

  1. Set up Nextcloud 28 using Docker Compose (standard setup with MariaDB and Nextcloud image).

  2. Create a custom app directory (animated_helloworld_app) with this basic structure:

    • appinfo/info.xml (with id animated_helloworld_app, namespace OCA\AnimatedHelloWorldApp)
    • appinfo/routes.php
    • lib/AppInfo/Application.php (with namespace OCA\AnimatedHelloWorldApp\AppInfo; and class Application)
    • lib/Controller/PageController.php
    • templates/main.php
  3. Copy the app into the running Nextcloud container:

    docker cp /path/to/animated_helloworld_app sandbox-app-1:/var/www/html/custom_apps/
    
  4. Set permissions:

    docker exec sandbox-app-1 chown -R www-data:www-data /var/www/html/custom_apps/animated_helloworld_app
    
  5. Enable the app:

    docker exec --user www-data sandbox-app-1 php /var/www/html/occ app:enable animated_helloworld_app
    
  6. Observe the error:

    PHP Fatal error: Cannot declare class OCA\AnimatedHelloWorldApp\AppInfo\Application,
    because the name is already in use
    in /var/www/html/custom_apps/animated_helloworld_app/lib/AppInfo/Application.php on line 13
    

    The error persists even after deleting animated_helloworld_app and replacing it with a new app under a different name — it still references the old animated_helloworld_app.

Jag har formaterat loggarna så de blir mer läsbara (listade och indragna). Jag har inte ändrat själva innehållet:


Log entries

Nextcloud

1 {
  "reqId": "lST5Ww6hyhjLppK1XdbR",
  "level": 2,
  "time": "2025-09-01T21:39:40+00:00",
  "remoteAddr": "172.18.0.1",
  "user": "--",
  "app": "no app in context",
  "method": "GET",
  "url": "/",
  "message": "Host localhost was not connected to because it violates local access rules",
  "userAgent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:142.0) Gecko/20100101 Firefox/142.0",
  "version": "",
  "data": []
}
5 {
  "reqId": "mlAJJNGW61OhBYwxF2eY",
  "level": 3,
  "time": "2025-09-01T21:44:27+00:00",
  "remoteAddr": "172.18.0.1",
  "user": "admin",
  "app": "PHP",
  "method": "GET",
  "url": "/ocs/v2.php/apps/dashboard/api/v2/widget-items?widgets%5B%5D=activity",
  "message": "Cannot declare class OCA\\\\MyHelloWorldApp\\\\AppInfo\\\\Application, because the name is already in use at /var/www/html/custom_apps/my_helloworld_app/lib/AppInfo/Application.php#10",
  "userAgent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:142.0) Gecko/20100101 Firefox/142.0",
  "version": "28.0.14.1",
  "data": { "app": "PHP" }
}
14 {
  "reqId": "cGP3hQcp29EevdmVrfZ2",
  "level": 3,
  "time": "2025-09-01T21:45:23+00:00",
  "remoteAddr": "172.18.0.1",
  "user": "admin",
  "app": "PHP",
  "method": "PUT",
  "url": "/ocs/v2.php/apps/user_status/api/v1/heartbeat?format=json",
  "message": "Cannot declare class OCA\\\\MyHelloWorldApp\\\\AppInfo\\\\Application, because the name is already in use at /var/www/html/custom_apps/my_helloworld_app/lib/AppInfo/Application.php#10",
  "userAgent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:142.0) Gecko/20100101 Firefox/142.0",
  "version": "28.0.14.1",
  "data": { "app": "PHP" }
}

(fler rader följer i samma mönster — alla med samma felmeddelande om att OCA\\MyHelloWorldApp\\AppInfo\\Application eller OCA\\AnimatedHelloWorldApp\\AppInfo\\Application redan är deklarerad.)


Web Browser

Firefox (Linux x86_64, Gecko/20100101).

Which image is this precisely (there are multiple images)?

Have you customized any PHP settings such as opcache revalidation?

Can you post the Application.php (at least everything up to the class line)?

And maybe post your Docker. Compose file.

Likely unrelated but please note that v28 reached end of support awhile back.