Fatal error: Class NAME not found in (....PATH)? - php

What may be the problem if i get the following error.
while i am extending a class i got this error
example:
class ModuleUser extends
AbstractModule
Fatal error: Class AbstractModule not found in (....PATH) ?
I have done most of the possibilities... But i can't resolve the problem.
any help will be thankful
thanks n advance
Fero

Prior to your definition of ModuleUser, import the file that contains the definition for AbstractModule.
require_once 'path/to/abstract_module.php';
If both classes are in the same file, then make sure you define the class ModuleUser after you define AbstractModule.

Related

php - how to remove namespace when calling object from independent class?

I'm calling an independent class's static function like: AnimeshPlugin::get_plugin_basename();
AnimeshPlugin is defined class... I'm using namespace AniPlugin\custom;
and when i call this function within this namespace class, error occured as:
Fatal error: Uncaught Error: Class 'AniPlugin\custom\AnimeshPlugin'
not found in
C:\xampp\htdocs\wordpress\wp-content\plugins\animesh-plugin\includes\config\custom\admin.php
on line 25
I don't want to add AniPlugin\custom\ before the class name.
Any suggestions??
Try the following:
\AnimeshPlugin::get_plugin_basename();
Look into Importing Namespaces in PHP and Global Space

FPDF - How to fix the "Fatal error: Call to undefined method PDF::FPDF()" Using Write_html

I am using this script http://fpdf.org/en/script/script50.php and I am getting the error:
Fatal error: Call to undefined method PDF::FPDF() in MyPath/html_table.php on line 55
it is this call to FPDF that is throwing the exception :
$this->FPDF($orientation,$unit,$format);
I don't understand why, knowing that the pdf class extends FPDF and I have the fpdf.php file in the same directory as the html_table.php file, is there any way to fix this error? Thank you
Fixed it.
I actually needed to replace :
$this->FPDF($orientation,$unit,$format);
by:
$this->__construct($orientation,$unit,$format);
The original script has this error, so for anyone wanting to use the script don't forget to fix this error first. Good luck.
I can't find $this->FPDF anywhere in the script you shared. When you extend a class, the extended class is in the $this of the class you extended it with.
The constructor of the extended class will always be ran when you create a new instance of this class unless you define a constructor yourself, which you did in the PDF-class as the script you shared shows.
If you want to run the constructor of the class you extended, you should do this from within the contructor of the extending class using parent::__construct(); which tells PHP that it should at that moment run the contructor of the parent class (the extended class).
This is already the case in the script you shared:
//Call parent constructor
parent::__construct($orientation,$unit,$format);
So when you run new PDF() it will call the contructor of the PDF-class, which will call the constructor of FPDF.
When you call the constructor again as mentioned in your answer by using the $this->__construct($orientation,$unit,$format); line, this will result in the PDF-contructor to be called twice.

PHP5.5: Fatal error: Cannot redeclare class

since I upgraded from PHP 5.2 to 5.5 I get an error I don't understand by now.
Fatal error: Cannot redeclare class sessionHandler in ... on line ...
Well before updating the PHP version this error didn't raise and redeclaring a class should be an error independent from PHP version as I guess. Further I always use require_once() which should help to avoid a mistake on that.
So just to make sure it doesn't be redeclared, I added a backtrace code block before that class declaration. So hopefully, I thought it would output twice, but I get only one backtrace output at all. Therefore it gets declared only once from my point of few.
Do I miss something? Any idea how to find the "real" issue?
Class "SessionHandler" already exists in the namespace as it's a class in PHP - http://php.net/manual/en/class.sessionhandler.php
Looks like the class was included in PHP 5.4 so it explains everything.
Try to think of some other name for the class or define a namespace.
If you create a namespace, something like..
namespace App;
class sessionHandler {
....
you won't get the error anymore but you will need to use App\sessionHandler whenever you're referring to your own class.

Cannot redeclare class

PHP says "Cannot redeclare class MyClass". Of course, class is defined only once. What else can cause this error?
A class included / required more then once. always use the include_once / require_once syntax for class & function files.
This was because my class was named Directory. It is probably a library class.

Fatal error: Class NAME not found in (....PATH)?

What may be the problem if i get the following error.
Fatal error: Class NAME not found in (....PATH) ?
I have done most of the possibilities... But i can't resolve the problem.
any help will be thankful
thanks n advance
Fero
Make sure that you have included the abstract class, it can implement, extens etc if the code isnt included.

Categories