Description
Q | A |
---|---|
Bug report? | yes |
Feature request? | no |
BC Break report? | no |
RFC? | no |
Symfony version | 4.0.8 |
Hello everyone!
Bug occurs when web profiler bundle is used.
Prior 4.0.8 if I have not configured string parameter as dependency I did get an error about it. Today I have a strange error about couldn't autoload a "string" class.
For example, I have a service:
class Service {
public function __construct(string $key) {
// some code
}
}
And I haven't configured it. So container doesn't know what exactly $key it needs. I don't use this service anywhere but have an error: Warning: include(string.php): failed to open stream: No such file or directory
(it is because my not PSR4 autoloader in queue), but I haven't an error about service configuration as I expected.
I've done a little research what happens.
In web-profiler-bundle/Resources/config/profiler.xml
:
<service id="debug.file_link_formatter.url_format" class="string">
<factory class="Symfony\Component\HttpKernel\Debug\FileLinkFormatter" method="generateUrlFormat" />
<argument type="service" id="router" />
<argument>_profiler_open_file</argument>
<argument>?file=%%f&line=%%l#line%%l</argument>
</service>
As you can see class="string"
but string is not a class really...
So sometimes (not only if configuration is missed) when autowiring is processing method ContainerBuilder::getReflectionClass()
is called. It calls ClassExistenceResource::isFresh()
which calls class_exists()
which triggers autoload.
I think we have two options to resolve this problem:
The first one is changing configuration of file_link_formatter
(may be wrap string to some special class with __toString()
method?).
The second one is changing ContainerBuilder::getReflectionClass()
to avoid getting reflection of internal types.
Or we can do both of course...
P.S.
I'm very sorry for my English. Please, ask any questions if my explanation is not clear.