I'm trying to run my travel project on AWS server.what I do is copy what I have done on the local computer to AWS server and change the .evn file when I run the project it is saying this error in the log file. (I did try to change permission in the folder but didn't work that also)
local.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'syntax error, unexpected ':', expecting ';' or '{'' in C:\MTASL\vendor\spatie\laravel-permission\src\PermissionRegistrar.php:33
Stack trace:
How can i fix this error.
updated
this the line that it says I did try to change what it says but didn't work
public function registerPermissions(): bool
{
try {
$this->getPermissions()->map(function ($permission) {
$this->gate->define($permission->name, function ($user) use ($permission) {
return $user->hasPermissionTo($permission);
});
});
return true;
} catch (Exception $exception) {
if ($this->shouldLogException()) {
$this->logger->alert(
"Could not register permissions because {$exception->getMessage()}".PHP_EOL.
$exception->getTraceAsString()
);
}
return false;
}
}
This line:
public function registerPermissions(): bool
is PHP 7 syntax. Remove ": bool" to have it work on older PHPs.
But chances are that the whole module requires a newer version of PHP than the one you have. The real solution is upgrade your PHP.
Look in your code at the line in question. The error tells you what the problem is. My guess without having seen anything is that the line ends in a : instead of a ;
Related
I have a strange problem in a symfony 5.3.10 app and i can't wrap my head around it.
If I trigger a 500 error, like so:
/**
* #Route("/", name="pvr_index", methods={"GET"})
*/
public function index(): Response
{
echo $a;
Where $a is not defined, in dev environment I get a nice error page.
I'd expect that in prod I would get a not so nice error page that just tells me that i have a 500 error. And this would happen correctly until some time ago, when something changed, but I don't know what.
Now instead I get no error, not even in the symfony server console, and the script execution would keep on going like nothing happened.
What I have tried:
Adding the supposed exception inside a try/catch:
try {
echo $a;
}
catch (\Exception $e)
{
dump($e);
die();
}
Nothing happens, the catch isn't triggered.
Creating an exception listener:
In services.yaml i have:
exception_listener:
class: App\Event\ExceptionListener
tags:
- { name: kernel.event_listener, event: kernel.exception }
And in ExceptionListener.php i have:
class ExceptionListener
{
public function __construct(Environment $engine) {
$this->engine = $engine;
}
public function onKernelException(ExceptionEvent $event)
{
dd($event->getThrowable()->getMessage());
}
}
Still nothing happens, the listener isn't triggered.
Everything works as expected in dev environment, the problem presents itself only in prod.
Looking at a phpinfo(); page I see that the error reporting is enabled, so I think that the problem lies in the symfony configuration.
I'm using php 7.4 and have no real access to the php.ini file
This is not a Symfony error (nor a PHP error for that matter).
On PHP 7.4, trying to output an undefined variable would only raise a notice, not a fatal error (code 500). Notices are silently swallowed up by the engine unless you configure your server to log them or output them, where you'd get something like:
Notice: Undefined variable: a in file xxx.php line Y
A try/catch won't do anything for you, since no exception is thrown for you to catch.
Even on PHP 8 or 8.1, this will only raise a warning like:
Warning: Undefined variable $a
You can see the result under version < 8 and >= 8 here.
I made loads of changes within my code and unfortunately kind of lost track what were the last one.. but I guess one of them created this weird problem.
When I'm trying to run php artisan serve, I get this error -
Parse error: parse error in /Users/Guest/admanager/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php on line 500
And the function that returns the error in helpers.php looks like this -
function factory()
{
$factory = app(EloquentFactory::class);
$arguments = func_get_args();
if (isset($arguments[1]) && is_string($arguments[1])) {
return $factory->of($arguments[0], $arguments[1])->times($arguments[2] ? null); // specifically, this is line 500
} elseif (isset($arguments[1])) {
return $factory->of($arguments[0])->times($arguments[1]);
}
return $factory->of($arguments[0]);
}
Please change as per below code,
$arguments[2] ? null TO $arguments[2] ?? null
The problem was that I just uninstalled xampp and it downgraded my locally running php version, hence the artisan serve didn't know how to handle that.
I recently migrated from age old amazon AWS SDK (v1.6.2) for PHP to the latest one. One thing I completely missed was Exception handling.
My first code.
$result = $this->S3Client->putObject($options);
if (!empty($result)) {
return !0;
}
But if upload fails, then it will throw an exception which will crash my PHP. So, I added exception handling next.
try {
$result = $this->S3Client->putObject($options);
return !0;
} catch(Exception $e) {
log_message($e->message);
return !1;
}
However, it seems that $e->message is protected.
Question: How can I get the error so that I can root cause what happened with the upload, once I move to production environment?
Try using:
log_message($e->getMessage());
More info here and here.
I have been looking around and following each tutorials,there is one which stands out. http://blog.lysender.com/2011/02/kohana-3-1-migration-custom-error-pages/ <-- i followed this tutorial and everything went smoothly
the error is being detected
the exception is being handled
but there has been an exception that i cant seem to find. im currently having this exception
Fatal error: Exception thrown without a stack frame in Unknown on line 0
all of my codes are thesame to the site-link. please help me.. im bugging around for this since ever, i've looked through here also Kohana 3 - redirect to 404 page but since im a beginner, its really hard understanding it. I've also found out that there is a major revamp from KO 3.0 to 3.1 how about KO 3.2? Thank you for your help guys :)
From the kohana source-code.
- > If you receive *Fatal error: Exception thrown without a stack frame in Unknown on line 0*, it means there was an error within your exception handler. If using the example above, be sure *404.php* exists under */application/views/error/*.
Maybe it helps. This probably has been fixed, but I'm not following the kohana development that much. It's related to pull request #246: https://github.com/kohana/core/pull/246 and this is the source: https://github.com/kohana/core/pull/246/files#L208L76
here is how I do it with Kohana 3.2
Add exceptions handling stuff in index.php
try
{
$request = $request->execute();
}
catch(Kohana_HTTP_Exception_404 $e)
{
$request = Request::factory('errors/404')->execute();
}
catch(Exception $e)
{
$request = Request::factory('errors/500')->execute();
}
echo $request->send_headers()->body();
Then write Errors controller
class Controller_Errors extends Controller
{
public function __construct($request, $response)
{
parent::__construct($request, $response);
}
public function action_404()
{
$this->response->body(View::factory('errors/404'));
}
public function action_500()
{
$this->response->body(View::factory('errors/500'));
}
}
Create 2 corresponding error pages (404.php and 500.php in views/errors)
Add new route to your bootstrap.php or use default one (depends on you project's structure), just make sure Controller_Errors can be reached when exception is thrown
Now every time you throws the exception in your controller, it will display the custom error page, like this
throw new HTTP_Exception_404;
I'm trying to log all application errors easily. Does ZendFramework have a plugin that can do this, or can it do this natively?
Type in your configuration:
phpSettings.log_errors = 1
phpSettings.error_log = "/path_to_yours_application_logs/php.log"
This puts all error logs to php.log file. It's common approach in production environment.
Zend includes standard error handling plugin that redirects to ErrorController.
Here are 2 solutions:
Create Zend_Controller_Plugin_ErrorHandler and register in bootstrap/controller
Create custom PHP error handler
also you can use in your Controller
try{
} catch(Zend_Exception $e){
echo $e->getMessage
(or log errors in log file using Zend_Log)
}
Zend_Log
Zend_Exception
To log all Error types (also PHP Fatal Error):
register_shutdown_function( 'myErrorHandler' );
function myErrorHandler() {
$error = error_get_last();
if( $error !== NULL) {
getMyZendLogger->log("got error: ".$error["message"], Zend_Log::ERR);
}
}
See How do I catch a PHP Fatal Error
Zend_Log::registerErrorHandler() (Zend-FW 1.12) catch not all errors