PHP Fetal Error: Cannot instantiate interface (solution)
Quick solution to a rare but not so obvious problem when instantiating classes that are manually included.

By. Jacob
Edited: 2022-08-31 07:18
Fatal error: Uncaught Error: Cannot instantiate interface keyworld\lib\db\db_interface in /var/www/test/test.php:29 Stack trace: #0 {main} thrown in /var/www/test/test.php on line 29
Getting a little rusty? This problem is easy to solve once you realize what is happening. It might happen when you are importing external PHP code that is part of another project and namespace, and you have made a mistake somewhere.
While the error message does not appear to be very helpful at first sight, if you think about it, the error actually tells you exactly what is wrong:
... Cannot instantiate interface ...
It tells you that you are trying to instantiate an interface somewhere in your code. The problem with doing that is that interfaces should not be instantiated — instead you need to pick the specific class that implements the interface, and then instantiate that directly.
I recently made this mistake myself, probably because it has been a while since I tried to instantiate a class that implements an interface manually. Once I realized my mistake, then it was an "ahhh, I already know this!" moment, and the problem was easily fixed.
Hopefully that helps.
Tell us what you think:
thank you m but i cannot fix that with
Psr\SimpleCache\CacheInterface
any idea about that ?