auraphp / Aura.Di

Dependency Injection System
MIT License
349 stars 63 forks source link

php 8: Trying to resolve a non-existent class gives an obscure and misleading error. #202

Closed far-blue closed 2 years ago

far-blue commented 3 years ago

When using php 8, trying to use/resolve a non-existent class - such as in a ContainerConfig via set() and then lazyGet() - gives the following obscure and misleading error:

Fatal error: Uncaught TypeError: get_parent_class(): Argument #1 ($object_or_class) must be an object or a valid class name, string given in /var/www/vendor/aura/di/src/Resolver/Resolver.php:209

In reality, get_parent_class() does accept a string and this hasn't changed in php 8. The important part of the error is 'valid class name', not 'string given'. This had me stumped for a good hour or more thinking the issue was php 8 when in fact it was a class name typo. It would be great if a better error could be generated by checking for the existence of a class before passing it to get_parent_class() or something. It's a fatal error so I'm not sure anything could be done after the error to catch and improve the message.

frederikbosch commented 2 years ago

Fixed in master, tag upcoming