Code: Select all
class OtherClass {
var $db = new mySQLClass;
function getResults($query) {
$db->Query($query);
}
}I know this is very newb, and I'm asking many questions. Thanks in advance for your patience.
Moderator: General Moderators
Code: Select all
class OtherClass {
var $db = new mySQLClass;
function getResults($query) {
$db->Query($query);
}
}Code: Select all
class Foo {
var $bar;
function Foo($bar) {
$this->bar = $bar;
}
function DoStuff() {
this->bar->devnet();
}
}
$bar = new Bar;
$foo = new Foo($bar);
$foo->DoStuff();Code: Select all
include('path/to/mySQLClass');
class OtherClass {
var $db = new mySQLClass;
function getResults($query) {
$db->Query($query);
}
}No. The problem is that you're trying to instantiate the object without using a method. You can only declare properties here... you can't run processes. Do it in the constructorwtf wrote:you need to make sure file with otherClass includes mySQLClass
Code: Select all
include('path/to/mySQLClass'); class OtherClass { var $db = new mySQLClass; function getResults($query) { $db->Query($query); } }
Code: Select all
<?php
class foo
{
var $obj;
function foo()
{
$this->obj = new someClass;
}
}
?>