Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
  • 19:46
    kocoten1992 starred PHP-DI/PHP-DI
  • Feb 04 18:47
    palansher commented #847
  • Feb 04 18:46
    palansher commented #847
  • Feb 04 18:43
    palansher commented #847
  • Feb 04 18:04
    SvenRtbg commented #847
  • Feb 04 05:23
    palansher commented #847
  • Feb 04 05:20
    palansher commented #847
  • Feb 04 04:27
    palansher commented #847
  • Feb 04 01:19
    palansher opened #847
  • Feb 02 09:58
    ErickJMenezes starred PHP-DI/PHP-DI
  • Feb 01 20:47
    nickolasburr starred PHP-DI/Invoker
  • Feb 01 11:06
    Amad3eu starred PHP-DI/PHP-DI
  • Feb 01 03:07
    easbarba starred PHP-DI/PHP-DI
  • Jan 31 08:01
    mfei58 starred PHP-DI/PHP-DI
  • Jan 31 07:35
    dingo-d commented #783
  • Jan 28 19:30
  • Jan 27 15:53
    mforest-gsu starred PHP-DI/PHP-DI
  • Jan 27 12:33
    rustamr1991 opened #846
  • Jan 27 12:28
  • Jan 27 12:09
    rustamr1991 opened #845
Anaël Ollier
Well, seems like at least these parts are okay to me. I suppose the problem does not occur with the classes defined in your container.php? What is the error you're getting?
== routes.php


use Slim\Http\Response;
use Slim\Http\ServerRequest;
use Slim\App;

//require \App\Action\HomeAction;
//require __DIR__ . '/../action/HomeAction.php';
//require __DIR__ . '/../action/AccountReadAction.php';

return function (App $app) {
    $app->get('/', \App\Action\HomeAction::class);

    $app->get(      '/api/v1/accounts',     \App\Action\AccountReadAllAction::class);
    $app->post(     '/api/v1/account/new',  \App\Action\AccountCreateAction::class);
    $app->get(      '/api/v1/account/{id}', \App\Action\AccountReadAction::class);
    $app->patch(    '/api/v1/account/{id}', \App\Action\AccountUpdateAction::class);
    $app->delete(   '/api/v1/account/{id}', \App\Action\AccountDeleteAction::class);

== Error Message

Slim Application Error

The application could not run because of the following error:
Type: RuntimeException
Code: 0
Message: Callable App\Action\AccountReadAction does not exist
File: /home/PROJECTNAME/vendor/slim/slim/Slim/CallableResolver.php
Line: 137

#0 /home/PROJECTNAME/vendor/slim/slim/Slim/CallableResolver.php(91): Slim\CallableResolver->resolveSlimNotation('App\\Action\\Acco...')
#1 /home/PROJECTNAME/vendor/slim/slim/Slim/CallableResolver.php(61): Slim\CallableResolver->resolveByPredicate('App\\Action\\Acco...', Array, 'handle')
#2 /home/PROJECTNAME/vendor/slim/slim/Slim/Routing/Route.php(358): Slim\CallableResolver->resolveRoute('App\\Action\\Acco...')
#3 /home/PROJECTNAME/vendor/slim/slim/Slim/MiddlewareDispatcher.php(73): Slim\Routing\Route->handle(Object(Slim\Http\ServerRequest))
#4 /home/PROJECTNAME/vendor/slim/slim/Slim/MiddlewareDispatcher.php(73): Slim\MiddlewareDispatcher->handle(Object(Slim\Http\ServerRequest))
#5 /home/PROJECTNAME/vendor/slim/slim/Slim/Routing/Route.php(333): Slim\MiddlewareDispatcher->handle(Object(Slim\Http\ServerRequest))
#6 /home/PROJECTNAME/vendor/slim/slim/Slim/Routing/RouteRunner.php(80): Slim\Routing\Route->run(Object(Slim\Http\ServerRequest))
#7 /home/PROJECTNAME/vendor/slim/slim/Slim/Middleware/BodyParsingMiddleware.php(50): Slim\Routing\RouteRunner->handle(Object(Slim\Http\ServerRequest))
#8 /home/PROJECTNAME/vendor/slim/slim/Slim/MiddlewareDispatcher.php(132): Slim\Middleware\BodyParsingMiddleware->process(Object(Slim\Http\ServerRequest), Object(Slim\Routing\RouteRunner))
#9 /home/PROJECTNAME/vendor/slim/slim/Slim/Middleware/RoutingMiddleware.php(58): class@anonymous->handle(Object(Slim\Http\ServerRequest))
#10 /home/PROJECTNAME/vendor/slim/slim/Slim/MiddlewareDispatcher.php(132): Slim\Middleware\RoutingMiddleware->process(Object(Slim\Http\ServerRequest), Object(class@anonymous))
#11 /home/PROJECTNAME/vendor/slim/slim/Slim/Middleware/ErrorMiddleware.php(89): class@anonymous->handle(Object(Slim\Http\ServerRequest))
#12 /home/PROJECTNAME/vendor/slim/slim/Slim/MiddlewareDispatcher.php(132): Slim\Middleware\ErrorMiddleware->process(Object(Slim\Http\ServerRequest), Object(class@anonymous))
#13 /home/PROJECTNAME/vendor/slim/slim/Slim/Middleware/ErrorMiddleware.php(89): class@anonymous->handle(Object(Slim\Http\ServerRequest))
#14 /home/PROJECTNAME/vendor/slim/slim/Slim/MiddlewareDispatcher.php(132): Slim\Middleware\ErrorMiddleware->process(Object(Slim\Http\ServerRequest), Object(class@anonymous))
#15 /home/PROJECTNAME/vendor/slim/slim/Slim/MiddlewareDispatcher.php(73): class@anonymous->handle(Object(Slim\Http\ServerRequest))
#16 /home/PROJECTNAME/vendor/slim/slim/Slim/App.php(208): Slim\MiddlewareDispatcher->handle(Object(Slim\Http\ServerRequest))
#17 /home/PROJECTNAME/vendor/slim/slim/Slim/App.php(192): Slim\App->handle(Object(Slim\Http\ServerRequest))
#18 /home/PROJECTNAME/public_html/index.php(5): Slim\App->run()
#19 {main}
So i included the routes.php which is the next step that would run, which you saw in the bootstrap.php earlier. But unless i manually put those includes (which are commented out) it gives me the above error message. But you can see it's not throwing errors for Slim\App or anything else, but it does for \App\Action\AccountReadAction
Anaël Ollier
I don't know Slim, but to me this looks more like an autoload issue than a DI issue. Are you sure you have an autoloader somewhere that's able to handle \App classes? Otherwise if it follows PSR-4 convention (which it should) you can add it to your composer.json like so: https://getcomposer.org/doc/04-schema.md#psr-4
In bootstrap.php I do have require_once __DIR__ . '/../../../vendor/autoload.php'; which is created by Composer. Here is my composer.json:
  "require": {
    "php": ">=7.1",
    "ext-json": "*",
    "monolog/monolog": "^2.0",
    "php-di/php-di": "^6.0",
    "selective/config": "^0.1.1",
    "slim/http": "^0.8.0",
    "slim/psr7": "^0.6.0",
    "slim/slim": "4.*"
  "require-dev": {
    "phpunit/phpunit": "8"
  "autoload": {
    "psr-4": {
      "App\\": "public/app/"
Anaël Ollier
So I assume your class \App\Action\HomeAction is located in public/app/Action/HomeAction.php, right? (just to be sure)
Sorry I won't be able to help you more for today (you know, Xmas and stuff) but I'll try to come back in a few days. In the meantime, try to use the debugger to trace how files are (auto)loaded and classes are resolved, you might figure out what's wrong more easily.
thanks for looking atleast. this is my first time using a php framework (which requires composer and php-di) so it's a lot all at once. no one does things simple anymore.. thanks again
oh and yes, you are correct, that is the path of the file
Anaël Ollier
It's a lot indeed. I've had my hard times too working with PHP-DI at first, but there's no magic int it and usually it's a PBKAC :)
that's my guess as well, but there is little documentation for people starting off. everyone assumes you know what you're doing. i didn't even know php-di was a thing until i started this project
Anaël Ollier
Trust me, once you'll get used to it, you won't want to do without ;)
The learning curve is just a bit steep
i usually can figure this out, but i'm just hitting a brick wall and don't know where to look for help at this point. can't tell if it's a slim issue, php-di issue (which you don't seem to think so) so i guess it's just how i have configure composer (autoload)
i have to say it's really tempting to just say screw it and just manually put the require lines in and be done with it
Does PHP-DI actually include the files or is that composer?
I figured out the issue. My project had the folder "public" but the web server had "public_html". once i fixed the path issue the problem was resolved. thanks for your help @nanawel
Anaël Ollier
Hi @gmariani. Glad you figured this out! So that was a path issue after all, nothing wrong with PHP-DI :)
Daniel Opitz
@gmariani It looks like an PSR-4 autoloader issue. Make sure that you defined the correct namespaces and paths in your composer.json file. Linux is case sensitive. For example if you have a namespace App\Action, then your directory should be named like this: src/Action/ and not src/action/.
Jack Price-Burns
Hello :wave: when using the autowiring to load classes, if the class can not be instantiated because of an exception the container just returns null, is this behaviour intended (I don't know if I've changed something) and is there any way I can make these exceptions get thrown out of the container so I can handle them myself?

Hi. I have this problem, when I upload my project to a host this error activates me: Fatal error: Not captured DI \ NotFoundException: No entry or class was found for 'App \ Controllers \ AuthController' in /home/vrfctuqw/myhonsting.com/ vendor /php-di/php-di/src/Container.php:135 Stack tracking: # 0 /home/vrfctuqw/myhosting.com/vendor/php-di/php-di/src/CompiledContainer.php(64) : DI \ Container-> get ('App \ Controllers ...') # 1 /home/vrfctuqw/myhosting.com/public/index.php(474): DI \ CompiledContainer-> get ('App \ \ Controllers ... ') # 2 {main} included in /home/vrfctuqw/myhosting.com/vendor/php-di/php-di/src/Container.php on line 135

Locally it works correctly, but in hosting I present this. I would like you to help me please

Định Nguyễn Thế
I has a problem when i call a magic menthod in a class.
Sandunika Fernando
Hi I have used "mnapoli/php-di": "~4.0", "container-interop/container-interop": "^1.1", for my application and now im moving to php 7 with "php-di/php-di": "6.0.11", "psr/container": "^1.0.0", I'm getting "Entry "Idfix\Contracts\RegistryInterface" cannot be resolved: the class is not instantiable Full definition: Object ( class = #NOT INSTANTIABLE# Idfix\Contracts\RegistryInterface lazy = false )" this issue please advice
Stay The Fuck Home
Hello! So, after doing composer update I get a notice that the package jeremeamia/superclosure is abandoned and php-di seems to require/depend on this package. Any solutions to this problem especially that the recommendation is using opis/closure and it's not advisable to edit composer.lock directly??
Maciej Holyszko
Vitalijus Trainys
hi, why dependencies still exists to jeremeamia/superclosure? Its abandoned?
Sorry, not read RTFM :)
Bram Van der Sype
When trying to compile my container, I'm getting a "The closure was not found within the abstract syntax tree" exception from jeremeamia/superclosure
Can anyone point me in the right direction of how to debug that? @mnapoli ?
The stack trace isn't exactly helpful
I previously had an error because I was using use ($var) in a closure, but took those out
Bram Van der Sype
Oh, apparently you can't use arrow functions
Jens Prangenberg
Hi everyone, does anybody have knowledge about php-di and zend expressive? "I got Cannot compile closures which import variables using the use keyword'", but i cant find an use statement for the given Delegator. Some ideas?
Bram Van der Sype
@mnapoli still using Slim v3 with the php-di bridge, I upgraded composer and now suddenly getting the error "Class 'AssociativeArrayResolver' not found in /var/www/html/cache/CompiledContainer.php on line 1210"
What could be causing that?
Bram Van der Sype
It happened in the upgrade from php-di 6.1 to 6.2, I'm guessing it has something to do with the change of the closure thingy
Adam Bosco

Hey all! I'm wondering if I can look up a key within a get()'d array in a autowire()->constructorParameter() somehow. This was my first stab, and I understand it doesn't work because get() is a definition helper, not an immediate lookup:

return [
  'config' => [
    'foo' => 'bar'

  'my.object' => autowire( MyClass::class )
    ->constructorParameter( 'foo', get( 'config' )[ 'foo' ] )

I understand that I could do this with a factory function, but I'm really curious as to if there is a way to do so without one?

How do I use PHP-DI in codeigniter 4
Hi, a query, how can I make a library I have generated, auto-inject into the application that uses it. Is this possible?

I tried something like this:

class CacheServiceProvider implements ServiceProviderInterface

 * @param Container $pimple
public function register(Container $pimple): void
    $pimple[CacheAdapter::class] = [self::class, 'getCache'];
But doesn't work!
Maciej Fikus

Hey guys, I've quick question as I do not understand it from docs.

How does @Inject work? It is said, that I can use it while I do not have control over object creation (i.e. some package).
The Object is created "by hand" somewhere (new Object(itsparams)) - then, I would like to inject some properties from container

I mean, it can't be used in this way, right? It can be used only if object itself is controllered by container?
are you here?
Mohamed Cherif Bouchelaghem
Seems that factory function doens’t accept callable like:
class MyServiceFactory {
   public function __invoke(ContainerInterface $container)
        //creation logic here!