Reply to Re: [PHP] Classes and Functions

Your name:

Reply:


Posted by Jasper Bryant-Greene on 11/03/05 01:59

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@album.co.nz
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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация