I've 3 class (Mysqliconn, Users and News).
Mysqliconn.class
Class Mysqliconn {
..connect to db
}
News.class
class News {
private $db;
public function __construct( Mysqliconn $db ) {
$this->db = $db;
}
public test() {
do something...
}
}
Users.class
class Users {
private $db;
public function __construct( Mysqliconn $db ) {
$this->db = $db;
}
public test2() {
do something...
}
}
In my php page
$db = new Mysqliconn();
$nw = new News( $db );
$us = new Users( $db )
$us->test2();
$nw->test();
My error
Catchable fatal error: Argument 1
passed to Users::__construct() must be an instance of Mysqliconn,
none given, called in ....\class\class.news.php
Now in my class Users I would like to to call a News class method, but I get an error if I try to istantiate the class News inside class Users.
How can I do this? Thanks.
Newsclass in yourUserconstructor?Usersdoesn't make sense. How do you have a singleUsers?