Closed Salman98 closed 2 years ago
Sorry, PHP cannot instantiate interface. https://www.php.net/manual/en/language.oop5.interfaces.php
We use GitHub issues to track BUGS and to track approved DEVELOPMENT work packages. We use our forum to provide SUPPORT and to discuss FEATURE REQUESTS.
Sorry, PHP cannot instantiate interface. https://www.php.net/manual/en/language.oop5.interfaces.php
We use GitHub issues to track BUGS and to track approved DEVELOPMENT work packages. We use our forum to provide SUPPORT and to discuss FEATURE REQUESTS.
I didn't find answer then I had no choice to post here . If you know already what i am missing then please let me know in future it might be useful for others too . Thanks
As far as I know, interfaces cannot be instantiated. You must instantiate a concrete class that implements the interface.
I think you mean to instantiate UserRepository
, the concrete implementation of UserInterface
.
class Home extends BaseController
{
public function __construct()
{
- $this->test = new UserInterface();
+ $this->test = new UserRepository();
}
public function index ()
{
$this->test->login('username', 'password');
}
}
PHP Version
8.1
CodeIgniter4 Version
4.2.6
CodeIgniter4 Installation Method
Manual (zip or tar.gz)
Which operating systems have you tested for this bug?
Linux
Which server did you use?
fpm-fcgi
Database
No response
What happened?
Error : Cannot instantiate interface .
I have following files
HomeController
userInterface
UserRepository
HomeController
In Config/AutoLoad.php I added these too
Steps to Reproduce
I have added code , if you try to follow it you will be able to reproduce it
Expected Output
the interface should work but it's not working
Anything else?
No response