Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

EventFellows's avatar

There seems to be another situation that causes this EXACT SAME ERROR but for a different reason!

Here is how I solved this other cause:

I had the same error but there were NO spaces anywhere in the .env file.

putting everthing into double quotes did NOT help in my case

In my case the reason was a tiny mistake in the config/services.php (but error can be reproduced in any of the files within config/... it does not need to be a custom config file)

in my case it was a ']' instead of a ')' - but I have also seen this same error with missing ',' (=comma) at line-end.

Very confusing as it is very hard to trace down from 'log' (which is probably from config/app.php in this small-letter notation in contrast to 'Log' in other places with a capital 'L')

Hope this m ight be of help to someone, too.

manu144x's avatar

Make sure the values in your .env file have no spaces :)

Just discovered this myself...

jbloomstrom's avatar

I could not figure out where the error was coming from, so I added the following to the top of Illuminate\Container\Container.php. Then I ran php artisan and it displayed the actual error message. In the end, it was a problem with a 3rd party config file. :/

namespace {

    use Monolog\Logger as Monolog;
    class log extends Illuminate\Log\Writer {
       function __construct()
       {
            $this->monolog = new Monolog("local");
       }
    }
}
4 likes
Bahjaat's avatar

@tomturton Thanks a lot. Just did git reset --hard and this hadn't fixed it. Saved me a lot of time!!

ryanaddams's avatar

It's been said in this thread, but double check config/app.php if you are having this issue - if you just installed (or tried to install) a package and cut and pasted something into the Services section that Laravel doesn't like.

Should the fact that this is throwing an exception when trying to log a bug be reported as a bug? It seems like it should be.

sitdhibong's avatar

I found this error when I added message that has spaces in .env file, please remove it.

nWidart's avatar

I just had this error, only via command line on a forge provisioned server. I found out it was because the following extensions were missing:

  • php-mbstring
  • ext-dom
  • php-zip

Hope this helps someone.

4 likes
adelin's avatar

I faced the same problem using php7 and laravel 5.2.

In my database.php config i had set: 'options' => [ PDO::MYSQL_ATTR_MAX_BUFFER_SIZE => 4718592 ],

As soon as i commented out that line it worked without any problem.

PS: on php 5.6 it says that MYSQL_ATTR_MAX_BUFFER_SIZE constant is not defined.

... crazy stuff

1 like
lukasoppermann's avatar

I accidentally moved the config folder into bootstrap/ which caused this error.

chargoy's avatar

I had a missing comma in config/app.php

jhoff's avatar

If you're stuck on this and it's not obvious like the .env spaces issue, @jbloomstrom 's post seems like the easiest way to get to the bottom of it. Just make sure you temporarily add parens around the Illuminate\Container namespace:

namespace {
    use Monolog\Logger as Monolog;
    ...
}

namespace Illuminate\Container {
    ...
}
3 likes
nestormata's avatar

If you are upgrading to 5.2, is very likely that your .env has as value somewhere multiple words not surrounded by "". Check your .env and make sure you surround everything that is not a simple word/value with "". The error is confusing because is thrown in an early state, before setting up the logs, and it happens after the upgrade because the previous version was more "relaxed" regarding that kind of values.

Kirkhammetz's avatar

Not to gravedig the topic but I was having this error on one of my vps only with one L5.1 installation, no error with 5.2+, after upgrading php to 7. I smashed my head for days on it then found it!

For everyone not having problem with quotes in .env neither in configuration files I found an answer here http://laravel.io/forum/12-03-2015-is-laravel-php7-compatible

"Make sure php7.0-mbstring is loaded"

just check it with "php -m" then install it using your system package manager and restart apache/nginx, that finally fixed for me.

1 like
BENderIsGr8te's avatar

I found the problem in my config/app.php file. I think it was because I copied and pasted from a web browser into the file and perhaps some invisible weird characters came with it. When I when through and re-tabbed the lines appropriately the problem was fixed. I would suggest checking any files you copy and paste from the web in your editor.

This happened to me just adding Cashier to L5.1. Also, I am using Atom if anyone is wondering with Valet.

cbj4074's avatar

I just encountered this in Laravel 5.1.

As @jbloomstrom and @jhoff suggest earlier in the thread, modifying Illuminate\Container\Container.php temporarily enables one to catch the underlying error that occurs prior to the logging error.

In my case, the underlying problem turned-out to be:

Symfony\Component\Debug\Exception\FatalThrowableError: Call to undefined method Closure::__set_state() in /var/www/example.com/laravel/bootstrap/cache/config.php:66

The problem seemed to occur suddenly, but I came to realize that it began when I executed php artisan config:cache, which creates the file bootstrap/cache/config.php, and this is the file in which the offending call, to an apparently-undefined function, Closure::__set_state(), is made.

I still don't know which library is at fault, but will update this post should I discover the culprit.

UPDATE:

The underlying problem in this instance is that one or more configuration files defines a closure. Laravel does not allow for this (see: https://github.com/laravel/framework/issues/9625 ), but the problem manifests only after the configuration is cached.

To fix the issue, hunt-down the offending key in bootstrap/cache/config.php, determine which configuration file the line is associated with, and remove any closures from the source file.

2 likes
yoyosan's avatar

I managed to find the error by using debug_backtrace().

Basically, what I did was to add a line above line 738 containing a call to Symfony's dump helper, like this:

        dump($concrete, debug_backtrace());
        $reflector = new ReflectionClass($concrete);

In my case, it was due to a config file calling a global translation helper, e.g. _('some text'), for which I was missing a php extension.

My setup is PHP 7.0.10 and Laravel v5.2.23.

2 likes
casenjo's avatar

I'm experiencing this same error with Envoyer. I made a new server on Forge (DigitalOcean, PHP 7) and now I'm trying to run its first deployment (Laravel 5.2 project), except it's with the mailer class in the ReflectionException. I checked for mbstring and pdo and they both are installed when php -m is run. I'm not sure where else to look to fix the issue :\

Update: I was able to fix it by enabling "install dev dependencies" in the Envoyer project settings. Can anyone explain why this fixes it?

melcap's avatar

For me, the problem was that I had a variable in my .env without the quotes and with a space API_NAME=my app name

which I changed to API_NAME="my app name"

and now it works fine.

james2doyle's avatar

Had a missing comma in a custom config.

Always lint code!

1 like
mustdie1bit's avatar

Try to remove bootstrap/cache/config.php if you run config:cache before

1 like
zoli's avatar

@OlLis, you rock! thanks for your post, it was helpfull for me - it saved my day;) !

Ltloafer's avatar

I just had this problem after upgrading to L5.2, and couldn't run artisan.

I was having trouble locating the error from the terminal but running phpunit identified it to the file and line number.

Benson's avatar

The post of @yoyosan is helpful! In my case, follow the debug_backtrace from start can notice that the real exception has been remake by laravel and crashed after that. Dump the real exception can find more hint.

//vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php@handle:92
public function handle($request)
    {
        try {
            $request->enableHttpMethodParameterOverride();

            $response = $this->sendRequestThroughRouter($request);
        } catch (Exception $e) {
            $this->reportException($e);

            $response = $this->renderException($request, $e);
        } catch (Throwable $e) {
            // dump the real exception
            dump($e);
            $e = new FatalThrowableError($e);

            $this->reportException($e);

            $response = $this->renderException($request, $e);
        }

        $this->app['events']->fire('kernel.handled', [$request, $response]);

        return $response;
    }

by the way, in my case I was missing the php7.0-mbstring extension

1 like
Bakharevich's avatar

@mustdie1bit Thank you a lot!

Guys, try to remove cache of config by at bootstrap/cache/config.php

I had the same problem after I cached my config.

JoolsMcFly's avatar

I just had this very issue when upgrading to 5.4 and dumping exception in Kernel.php helped:

    public function handle($request)
    {
        try {
            $request->enableHttpMethodParameterOverride();

            $response = $this->sendRequestThroughRouter($request);
        } catch (Exception $e) {
            $this->reportException($e);

            $response = $this->renderException($request, $e);
        } catch (Throwable $e) {
            dump($e); // <================== this guy!
            $this->reportException($e = new FatalThrowableError($e));

            $response = $this->renderException($request, $e);
        }

        event(new Events\RequestHandled($request, $response));

        return $response;
    }

which showed me:

Error {#95 ▼
  #message: "Call to undefined method App\Application::share()"
  #code: 0
  #file: "/media/code/site/vendor/adamwathan/bootforms/src/AdamWathan/BootForms/BootFormsServiceProvider.php"
  #line: 34
  -trace: {▶}
}

Turns out it was due to us not having bumped adamwathan/bootforms to 0.8.4.

mickaelpch's avatar

Had the same error as @boovad when upgrading from 5.1 to 5.2 with PHP 7.0.15 : Undefined class constant 'MYSQL_ATTR_MAX_BUFFER_SIZE'

@jhoff answer helped me find the reason :)

Please or to participate in this conversation.