RE: [PHP] Global class

From: Date: Wed, 28 Jun 2000 12:35:17 +0000
Subject: RE: [PHP] Global class
Groups: php.general 
Request: Send a blank email to php-general+get-3543@lists.php.net to get a copy of this message
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

« previous php.general (#3543) next »