PHP Fatal error: Class not found - php

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

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

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

Related

neo4j graphaware php-client: class not found

When I tray to access my neo4j-DB via Graphaware's php-client using http-protocol, I get the following error message:
Fatal error: Class 'GraphAware\Common\Result\AbstractRecordCursor' not found in ...
On the other hand when I'm using the bolt-protocol t says:
Fatal error: Uncaught Error: Call to undefined method GraphAware\Bolt\Result\Result::getResult() in...
At the beginning of my code I have used
require_once 'vendor/autoload.php';
use GraphAware\Neo4j\Client\ClientBuilder;
so I thought the classes should be autoloaded which is obviously not the case.
What's wrong?
I have solved this issue by replacing the respective syntax for queries of the example-files by one out of the README.

Fatal error: exactly/the/good/way/class not found

I got the Fatal Error:
Fatal error: Class 'app\Autoloader' not found in C:\wamp64\www\WE\index.php
In other words:
Fatal error: exactly/the/good/way/class not found
begin of my script index.php
<?php
use \app\Autoloader;
Autoloader::register();
Begin of my autoloader script:
namespace app;
class Autoloader{...}
Arborescence:
Racine local server
app
[...]
Autoloader.php
index.php
Why this fatal error ?? The way mentionned in the error php is right...
Thaks for help !
The use statement will need to have the class available first. Since you haven't added the autoloader, you'll have to require_once the PHP file containing the autoloader, then use the class to import it into your namespace.
After the autoloader is present, it will have the responsibility of finding and loading the classes as they're use'd.

PHP Fatal error: Class 'Swift_Validate' not found

I am trying to use Swift_Validate::email($email) and I get a php error: PHP Fatal error: Class 'Swift_Validate' not found.
I have the latest version of swiftmailer. Is there some preference settings I need to do?
I have tried including the Validate.php file, but then I get the error: PHP Fatal error: Class 'Swift_DependencyContainer' not found.
I include DependencyContainer.php and I get the error PHP Fatal error: Class 'Swift_DependencyException' not found.
I include DependencyException.php and I get the error: Class 'Swift_SwiftException' not found.
I include SwiftException.php and I still get the same error.
I think I must not have the preferences set up correctly. I am calling:
"require_once($dir.'/swift/swift_required.php');"
The code I am using for the validation is:
if (!Swift_Validate::email($email))
{ $error = true; }
Any help would be greatly appreciated. Using latest Apache and PHP.
Try require_once dirname( __FILE__) . '/lib/swift_required.php'; to use the built-in autoloader, where lib is subfolder of folder where is the current file ( for default directory structure of the library )

PHP Fatal error: Class 'AlbumTest\Bootstrap' not found

I am learning framework2 and I am following this:
http://framework.zend.com/manual/2.0/en/user-guide/routing-and-controllers.html
But I'm getting this error:
PHP Fatal error: Class 'AlbumTest\Bootstrap' not found in
/home/ben/ZendSkeletonApplication/path/to/zf2-tutorial/module/Album/test/AlbumTest/Controller/AlbumControllerTest.php
on line 23
It sounds like a namespace problem. Most likely your controller is in the namespace AlbumTest but you called Bootstrap instead of \Bootstrap. The difference is the latter will look in the root of your namespace for that directory.

fatal Error when using pear pager !

i used PEAR Pager in my Projects . it's works fine in my local server but when i upload it to hosing server it's gaves me fatal error :
Fatal error: Cannot redeclare class PEAR_Common in /usr/lib/php/PEAR/Common.php on line 1123
i don't know what's the problem , how can i solve that ?!
The error message says it all. It seems like the class PEAR_Common is loaded twice. Check your code for includes/requires of this class.
If you are using other pear packages that might load (include) this class before you include your Pear_Pager class then this might be the problem.
Regards,

Categories