3

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...

5
  • 2
    Is there an InvitationNotifier class in InvitationNotifier.php? Does it use a namespace? Commented Jan 21, 2015 at 18:30
  • Yes, there is and no it does not use a namespace. abstract class InvitationNotifier implements Notifier { } Commented Jan 21, 2015 at 18:34
  • What happens when you use the absolute path to the class? Commented Jan 21, 2015 at 18:53
  • 1
    Did you place any of your requires inside of a container like a function or a class? I don't know how this scenario would play out: Inside a function, you require_once InvitationNotifier. It is included and the function ends. Now, outside the function, you require_once it again. It was already required, but the class definition was contained inside the function, so it doesn't exists when you tried to use it. Changing to require will define the class in the function (one define) and outside it (a second define - error). Commented Jan 21, 2015 at 18:53
  • Well actually the require/require_once is outside the class definition and outside any function. I didn't understand your point, if you can elaborate a little Commented Jan 21, 2015 at 23:36

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

Comments

1

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');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.