Aware of class resolution syntax of PHP 5.5 for Laravel 5

by Pete Houston

According to the documentation of the latest release Laravel 5.0 (as of the time when this article is written), at

It requires :

  • PHP >= 5.4

However, if you follow any tutorial or guide on Laravel 5 Events, you will see the event binding defined,

protected $listen = [
‘’ => [
UserWasRegistered::class => [

Be aware of the syntax ::class , which is the class name resolution syntax that is mentioned as new feature of PHP 5.5,

If you are, by accident, running a server with PHP < 5.5, the artisan command will bump with the following error.

syntax error, unexpected ‘class’ (T_CLASS), expecting identifier (T_STRING)

The solution is simple, instead of using ::class syntax, just define events as strings. That’s all you need to do. Do it your way.

For example:

‘user.registered’ => [

Probably, there are several ways to do it. I bet you can find more of it.

Anyway, have fun ! ☺

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.