RE: [PHP] Global class

From: Date: Thu, 01 Jan 1970 00:00:00 +0000
Subject: RE: [PHP] Global class
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-3545@lists.php.net to get a copy of this message
Thank you very much. It's working fine now. And yes, that () stuff doesn't work. with regards, Tijmen On Wed, 28 Jun 2000, Stewart Taylor wrote: > You need to declare global variables in each function that you want to use > them in. > From the code your idea is that declaring $error global once in setError > means it will be defined global everywhere. This is not the case. > > i.e. You need to declare it as a global var in testcode(). > function testcode() { > global $error; > $error->addError("Test1","1"); > $error->addError("Test2","2"); > $error->viewError("1"); > } > > Also I don't believe you need the () in the class Error declaration > class Error()<-- > > -----Original Message----- > From: Hennink Tijmen 44541 [mailto:hennink@hio.hen.nl] > Sent: 28 June 2000 09:52 > To: php-general@lists.php.net > Subject: [PHP] Global class > > > Hi, > > can anyone tell me why this isn't working properly? > global.php3 > <? > $error = new Error; /* A class */ > function setError() { > global $error; > } > ?> > > <? > include("global.php3"); > setError(); > function testcode() { > $error->addError("Test1","1"); > $error->addError("Test2","2"); > $error->viewError("1"); > } > ?> > > <? > class Error() { > function addError($mes,$val) { > echo $mes; > } > > function viewError($val) { > echo $val' > } > } > ?> > > PHP give the following warnings > > Warning: Object error not found in Object.php3 on line 28 > > Fatal error: Member function used on a non-object in Object.php3 on line > 28 > > with regards, > > Tijmen Hennink > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > >

« previous php.general (#3545) next »