Re: Classes and Functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 2005-11-02 at 18:56 -0500, Unknown Unknown wrote:
> Hi everybody i have a class that i reference with:
> $DB= new DBInterface;
> outside a function it works fine, but using $DB inside a function changes
> the data type i think... i get an error saying i'm using a method on a
> non-object...
> any help appreciatted

If you are attempting to access the variable $DB inside the function
scope, like this:

$DB = new DBInterface;

function doSomething() {
	$DB->doSomethingElse();
}

Then it will not work unless you either pass $DB to doSomething(), or
declare $DB as a global at the start of the function. Like this:

function doSomething() {
	global $DB;
	$DB->doSomethingElse();
}

Or access $DB through the globals superglobal. RTFM.

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: jasper@xxxxxxxxxxx
w: http://www.album.co.nz/
b: http://jbg.name/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux