6

Short version

I'm getting this error, when I run php artisan serve and visit my home page:

ReflectionException (-1)
Class setEventDispatcher does not exist

Details

Laravel version: 5.6.39 Environment: local OS: macOS Mojave 10.14.2

It started, when I got an error using npm (in another project), so I reinstalled Node (this way).

After doing that, then this project (in question) couldn't be started. I was getting this error, when running php artisan serve:

dyld: Library not loaded: /usr/local/lib/libpng16.16.dylib with anything php related
Referenced from: /usr/local/bin/php
Reason: image not found

That error was resolved by updating and upgrading brew.

Then I was capable of starting the project (php artisan serve). But when I visit the home page, this error was shown:

ReflectionException (-1)
Class setEventDispatcher does not exist

If I follow the stack trace, then I can see that it was this line (from my homeController) that triggered the error:

if( ! Auth::check() ){
  return view( 'pages.home' );
}

If I commented that out, then the same error occured from another place, where the Auth-module was being used.

Here's the stack trace:

setEventDispatcher does not exist error

Does anyone know how to resolve this? I can't find any promising results on Google, - and I have no idea why this happens... :-/

Addition1

I tried composer clear-cache and deleting the vendor-folder, and then doing a composer install and the problem still occured.

I also checked my Service Providers, as Marcus suggested, - but I don't really know what to look for in there. It all looks pretty regular (no fancy if-statements or anything).

Addition2

I realized, that I couldn't connect to my database using Sequel Pro. And it was because Brew had updated my MySQL-version from 5.5 to 8.0.

That was resolved by doing something along these lines (I did a bunch of stuff, so I might be missing a coulple of steps):

brew unlink mysql
brew install mysql@5.7
brew switch mysql 5.7.21
brew link mysql

and I could then verify the version with mysql --version. I also had some permission issues with that MySQL-version-change, but I'm emitting that, so this doesn't get too long.

Addition3

I tried disabling the Laravel Debugbar (by deleting it from composer.json, deleting composer.lock and vendor and then running composer install). And that fixed it!! ... But!

When I later tried to install Barryvdh's IDE Helper, then the exact same error came back!?

I performed these three steps, to install the IDE Helper (and re-introduce the error):

  1. Run this command from the root of my directory: curl https://gist.githubusercontent.com/barryvdh/5227822/raw/4be028a27c4ec782965bb8f2fdcb4c08c71a441d/_ide_helper.php -o _ide_helper.php

  2. Add these lines to app/Provider/AppServiceProvider.php:

...

if ($this->app->environment() !== 'production') {
  $this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
}
  1. Run this command: composer require --dev barryvdh/laravel-ide-helper

So I'm back at this error:

ReflectionException (-1)
Class setEventDispatcher does not exist

... The stack trace is identical to the one shown previously (sprung from Container.php).

Zeth
  • 2,273
  • 4
  • 43
  • 91
  • No idea if this will help you, but I was getting the same errors `Class setEventDispatcher does not exist` after trying to upgrade from 5.5 to 5.6, I later realised I didn't follow all the steps in Laravels upgrade page: https://laravel.com/docs/5.6/upgrade after I done that, and again for 5.7 my app was working again. – Mint Jan 08 '19 at 11:23

7 Answers7

3

So this is what usually fixes it for me

  1. Reinstall composer dependencies by removing vendor folder and composer.lock. Then run composer clear-cache and then composer install (this is usually the problem)

  2. Check that all service providers are imported correctly in app.php under directory config

  3. Make sure that your service providers are not importing something that does not exist, for example if you register a service provider in production but is only installed as dev:

    if (env('APP_DEBUG')) { $app->register(Barryvdh\Debugbar\LumenServiceProvider::class); }

Marcus
  • 1,850
  • 1
  • 12
  • 24
  • 1
    I did step 1, - and it made me realize that the home page renders as it should, if the user is not logged in. So it must be something with the Auth-package/module. I looked through app.php, but I can't see anything that should be wrong in there. However, - I don't have that much experience with service providers. So I only touch it, if some guide tells me to (and the I do what it tells me without questioning it). ... So it didn't resolve my problem. Good suggestions, though. :-) – Zeth Dec 28 '18 at 22:43
  • Glad it helped! Would appreciate if you marked it as the right answer to :) – Marcus Dec 29 '18 at 07:26
  • I don't think you read my comment. I performed all three of your steps and it didn't help. :-/ I've added further details in the question. – Zeth Dec 29 '18 at 17:51
  • Now I see, okay! – Marcus Dec 30 '18 at 09:34
  • Yep. Doesn't change anything. :-( – Zeth Dec 30 '18 at 14:27
3

Tried every solution, none of them worked.

Finally, i realised that when trying to upgrade php to 7.3.3 it was infact a network error that caused the fail. Read the logs, tried again, restarted valet and tried again.

It works now.

Upgrading to 7.3.3 was the solution indeed.

Thank you!

Frederik B.
  • 196
  • 3
  • 11
  • Upgrading 'away from' PHP-version 7.3.0 worked for me as well. It's stated [here](https://github.com/laravel/framework/issues/27052) – Zeth Sep 29 '19 at 13:57
2

If you use valet, I solved it running

valet restart and all works fine.

cheers!

cvallejo
  • 21
  • 4
1

The fix for me was to update PHP to 7.3.3 and then restart valet. Apparently this was a bug with php 7.3

https://github.com/laravel/framework/issues/27052

Hope this helps

JeffBeltran
  • 709
  • 8
  • 16
0

I got some idea... I've just run into this problem after reconfiguring my apache virtual host ports, so I restarted apache/httpd again, and the problem went away. Might it be related with the server environment?

CCK
  • 23
  • 5
  • Hmm... I'm running on my own local environment. But maybe that's the issue. I tried restarting the server (many times), and it doesn't make a difference. – Zeth Dec 29 '18 at 17:24
0

I am facing the same issue in mac book pro. My system configuration is PHP 7.3, MySQl and I use SQL Pro. I have implemented all the above methods but nothing gets worked. The issue is still a mystery for me but for temporary I have solved this issue using artisan command as bellow.

php artisan serve

Its Allow me to run the project on http://localhost:8000 Hope this can help to solve this issue.

0

Try to restart PHP. When I reboot my Mac, then this happens. After restarting PHP everything starts to work.

sudo brew services restart nginx