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

skovmand's avatar

Target not instantiable - only on my server.

Hi!

I have just made a nice NotifierServiceInterface with a concrete implementation in my class PusherNotifier. I've added

$this->app->bind('Traeningsprojekt\Notifier\NotificationServiceInterface', 'Traeningsprojekt\Notifier\PusherNotifier');

to the register()-method in AppServiceProvider.php, and the ServiceProvider is listed in config/app.php.

When I do App::make('Traeningsprojekt\Notifier\NotificationServiceInterface'); in php artisan tinker, I get the PusherNotifier class on my Homestead dev machine, but on my server I get this error:

>>> App::make('Traeningsprojekt\Notifier\NotificationServiceInterface');
Illuminate\Container\BindingResolutionException with message 'Target [Traeningsprojekt\Notifier\NotificationServiceInterface] is not instantiable.'

I have tried php artisan optimize and php artisan optimize --force as well as php artisan clear-compiled.

However it works both places, if I manually write in php artisan tinker:

App::bind('Traeningsprojekt\Notifier\NotificationServiceInterface', 'Traeningsprojekt\Notifier\PusherNotifier');
App::make('Traeningsprojekt\Notifier\NotificationServiceInterface');

So it seems to me that the binding is not being registered at all on the server! Maybe there is a compiled file "stuck" somewhere?

Can anyone help me get further with this?

0 likes
3 replies
skovmand's avatar

Update:

I can actually delete ServiceProvider files from my server, and the site continues to work, as if they are still there. Their bindings still exist. It is as if the site is reading the files from somewhere else!

Is there a secret cache file or something?

skovmand's avatar
skovmand
OP
Best Answer
Level 3

AHA! Solved it, finally.

I thought the compiled.php and services.json files were in /vendor/. I found them in the folder /storage/framework/ and manually deleted them. Now everything is normal and I am calm again.

php artisan clear-compiled doesn't remove those files - only those in /vendor.

Maybe it's old files from Laravel 4, which have just been hiding in there?

skovmand's avatar

Update #2:

This is the real cause. Laravel 5.0.16 updated the path to the compiled.php file: That was the problem all along.

Laravel 5.0.16 was compiling files to /vendor/, but the old compiled-files were in /storage/framework/ and were taking precedence over the new ones.

See: http://laravel.com/docs/5.0/upgrade#upgrade-5.0.16

In bootstrap/autoload.php change it to:

/*
|--------------------------------------------------------------------------
| Include The Compiled Class File
|--------------------------------------------------------------------------
|
| To dramatically increase your application's performance, you may use a
| compiled class file which contains all of the classes commonly used
| by a request. The Artisan "optimize" is used to create this file.
|
*/

$compiledPath = __DIR__.'/../vendor/compiled.php';

if (file_exists($compiledPath))
{
    require $compiledPath;
}

Please or to participate in this conversation.