PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I keep getting the error above on the line marked below (not the actual code, obviously). I have been using an '&' with the database object when making objects. It works until I get to the line marked below as 'problem line'. I don't understand the '&'. Please tell me what I'm doing wrong. Thanks.
$db = new Database;
$mod = new Module(&$db);
class Module {
var $db;
function Module(&$db) {
$this->db = &$db;
}
function make_objects() {
$obj = new Object(&$db);
}
}
class Object {
var $db;
function Object(&$db) {
$this->db = &$db;
}
function do_query($query) {
$this->db->query($query); // problem line
}
}
class Module
{
var $db;
function Module(&$db) { $this->db = &$db; }
function make_objects() { $obj = new Object(&$db); }
}
class Object
{
var $db;
function Object(&$db) {$this->db = &$db; }
function do_query($query) { $this->db->query($query);} // problem line
}
$db = new Database;
$mod = new Module(&$db);
whenever you get that error it means that you are using something that isn't created and isn't PHP therefor it's a class or a function that has yet to exist.
i get it all the time when i shotgun code a new plugin for my framework.
function make_objects() {
$obj = new Object($this->db);
$obj->do_query("SELECT * FROM mytable");
}
If you are using PHP5 you don't need the ampersands. For PHP4 you have is correct with the &ersand on the parameter and another ampersand on the assignment.