Auto-Loader Not Working GAE Php 8.2

Hello there,

I'm reaching out regarding an issue I encountered after successfully deploying my application using PHP 8.2 on Google App Engine. It seems that my application is unable to locate any auto-loaded classes. Previously, I managed to meet PSR-4 Autoloading standards by specifying the workspace folder in the composer.json file. However, even with this setup, the issue persists.

Would you have any insights or suggestions on how I can resolve this matter within the Google App Engine environment?

Thank you in advance for your assistance.

composer.json:

Screenshot 2024-03-18 at 2.44.58 PM.png

Classes folder in root folder:

Screenshot 2024-03-18 at 2.45.20 PM.png

Namespace declaration in Sanitizer.php:

Screenshot 2024-03-18 at 2.45.34 PM.png

Use statement & Class/Method called in Index.php:

Screenshot 2024-03-18 at 2.45.48 PM.png

Error found in Google Logger:

Screenshot 2024-03-18 at 2.54.30 PM.png

 

1 1 72
1 REPLY 1

Hi @chikondi,

Welcome to Google Cloud Community!

Mismatch between composer.json configuration and class location/naming.

Solutions:

  1. Verify Path: Ensure Sanitizer.php resides in the directory specified by composer.json (e.g., workspace/classes/).
  2. Check Case Sensitivity: Match the casing in composer.json (Abre//) to the actual class name (Abre\Sanitizer).
  3. Clear Autoload Cache (if needed): Run composer dump-autoload to refresh the autoloader.

Code Fix (depending on the cause):

  • Path Mismatch: Update composer.json path accordingly (e.g., remove trailing slash if Sanitizer.php is in workspace/).
  • Case Mismatch: Fix casing inconsistency in either composer.json or the class name.

Additional Tips:

  • Include require_once 'vendor/autoload.php'; at the beginning of relevant scripts.
  • Consider using relative paths within Sanitizer.php for dependencies (optional).