eureka
eureka

Reputation: 69

PHP Fatal error: Class not found

I've a very strange issue. In one class "SMSNotifier" I have

require_once (__DIR__ . "/../InvitationNotifier.php");
[...] 
class SMSNotifier extends InvitationNotifier {
[...] 
}

this class is included in another script which is called from the cli. When calling this script I get

PHP Fatal error:  Class 'InvitationNotifier' not found in [...]/include/classi/notifiche/notifiers/SMSNotifier.php on line 12

The strange thing is that if I replace the require_once with a require I get instead

PHP Fatal error:  Cannot redeclare class InvitationNotifier in [...]/include/classi/notifiche/InvitationNotifier.php on line 11

What could be the issue here?

Thank you in advance for any thought. I've ran out of them...

Upvotes: 3

Views: 4995

Answers (2)

doublejosh
doublejosh

Reputation: 5774

You should not just be loading up files like it's 1990. Use Composer (PHP) and follow PSR-4 http://www.php-fig.org/psr/psr-4

composer.json

{
  "autoload": {
    "psr-4": {"InvitationNotifier\\": "lib/"}
  }
}

index.php

require_once('autoload.php');

Upvotes: 1

eureka
eureka

Reputation: 69

I've continued trying to understand the issue and I've found out that there was a circular dependency. I've "cut it" down and the issue is gone. Hope this can help someone

Upvotes: 3

Related Questions