1

I create PHP-DI container with PDO. It looks like this:

$containerBuilder->addDefinitions(__DIR__ . '/ConfigPDO.php');

my ConfigPDO definitions:

   // ConfigPDO.php

    return [

        myPDO::class => function () {
            return new myPDO();
        }

    ];

And I also have myPDO class:

//myPDO.php
class myPDO extends PDO {}; 

I have placed class myPDO in separate file myPDO.php in the same Config folder. However, when I use in ConfigPDO.php syntax: use Config\myPDO; I have an error: Fatal error: Uncaught DI\NotFoundException: No entry or class found for 'myPDO'

and if I make include('myPDO.php'); everything works fine. Is it right to use include instead of use in this place?

szerz
  • 247
  • 2
  • 10

1 Answers1

1

I did not understand your question well, but in any case, you should look for the difference between USE and INCLUDE and in what situations each one is used. I think this link can help you Use vs Include in PHP

  • Thank you for an answer. I know that I have to use 'use' syntax here because I do the import of the specified class to the current scope. However.. .it doesn't works this way with my PHP-DI definition. – szerz May 11 '19 at 08:04
  • I have found an issue. It was a problem that I have used 'PDO' instead of '\PDO'. Thank you for your support once again! – szerz May 11 '19 at 08:12