I am using laravel 5.5, I want to use CrondJobs but none of my classes found in my php file
//This Is My Name Space
namespace App\Http\Controllers\Crons;
//Using Jalali but Class Not Found
$date =\Morilog\Jalali\Jalalian::now()->format("Y/m/d " );
This is my error in my error_log
PHP Fatal error: Uncaught Error: Class 'Morilog\Jalali\Jalalian' not
found in /home/micacoco/crons/cron.php:29
The possible causes of this error can be:
Class doesn’t exist
The class name case is not the same for example - Jalalian.php and jalalian.php are not the same even when the class name case is the same check to confirm that the 'use' statement has the right letter case.
wrong namespace
Related
In the asset file in utilities, I put the namespace APP\Utilities correctly, but when I use the asset::get() object, for example, it gives an error.
#Meanwhile, I am just learning MVC :)
I don't understand why my machine running PHP 7.2.9 gives this error:
Fatal error: Cannot declare class Error, because the name is already in use in controllers\error.php on line 3
I have a file named controllers/error.php which contains:
<?php
class Error {
function __construct() {
echo 'Error: 404 not found the file.';
}
}
Meanwhile, I have a file named /index.php which contains:
require "controllers/error.php";
$controller = new Error;
Even if I change from require to require_once "controllers/error.php", it still keeping reporting the same message.
Error is a built-in class in PHP 7.
As such, you cannot make a class Error {}.
Rename the class, or put it in a namespace to avoid conflict.
(Or, as a third option, you could consider using/extending the built-in class instead of making your own error handling system from scratch.)
As already stated, 'Error' is a built in class in PHP 7. You have several options:
(1) Put your class in a namespace
<?php
namespace MyApp\Errors;
class Error {
}
Then when you use it ...
$error = new \MyApp\Errors\Error;
(2) Use a different name like AppError.
<?php
class AppError {
}
Recommended:
In general, classes should be placed into files that are the exact same name
as the class itself. Class "AppError" should be in file "AppError.php"
If you are using namespaces, then the namespace should match the dir where
the file is located. If you have MyApp\Errors, you would put that into "MyApp/Errors/Error.php".
class "MyApp\Errors\Error" would be in dir MyApp/Errors/Error.php.
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
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.
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.