Setting a class global
| From: | Tijmen Hennink | Date: | Tue, 27 Jun 2000 21:57:02 +0000 |
| Subject: | Setting a class global | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-3462@lists.php.net to get a copy of this message | ||
Hello,
currently I have a project for school where we are developing a system
for placing very userfriendly document on the internet.
It has to be something like the xdrive (www.xdrive.com).
Now we are thinking about how the fetch all the errors that can occur.
Whe have written the following Errorclass
<?
if(!$Error_php3) { $Error_php3 = 1;
/*
* @author : Tijmen Hennink
* mail : hennink@hio.hen.nl
*/
class Error {
var $errorarray;
var $size; /* representing the size of the array */
/*
* Constructor, setting the size to 0
*/
function Error() {
$this->size=0;
}
/*
* Function for adding a error in the array.
* errorniveau is the errorlevel
* We have the following code's
* 0 All errors(including PHP)
* 1 All systemerror's
* 2 frontend error's
*/
function addError($message,$errorniveau) {
$this->errorarray[$this->size] = array($message,$errorniveau);
$this->size++;
}
/*
* Function for showing all the error's that correspondent to the
* admitted errorniveau and above
* eg errorniveau would show all the error's with 1 and 2 as errorniveau
*/
function viewError($errorniveau) {
$foutmeldingen = array();
for($i = 0;$i < $this->size; $i++) {
if($this->errorarray[$i][1] >= $errorniveau) {
$foutmeldingen[$i]= $this->errorarray[$i][0];
}
}
$this->javaerror($foutmeldingen,$this->size);
}
/*
* Function for showing all the error's in a javascript alert
* box
*/
function javaerror($message,$size) {
echo "<SCRIPT LANGUAGE=javascript>\n";
echo "var errormessage;";
for($i = 0;$i < $size;$i++) {
if($i== 0) {
echo "errormessage = " . "\"" .
$message[$i] . " \\n\"" .
"\n";
}
else
{
echo "errormessage += " . "\"" . $message[$i] . "\\n\"" .
"\n";
}
}
echo "alert(errormessage)";
echo "</SCRIPT>\n";
}
}
}
?>
We also have some other classes like link and link_list.
The problem is this.
We want to create one instance of the Error-class for each PHP-thread.
So if link_list will create an instance of link , the instance of Error
have to be the same as in link_list.
When we can do this , we can store all the error's that the system found
in this class and when the GUI has to react to the user then we want to
show all the errors.
Thus we want to make the class Error global but we don't really know how
to do this in a proper way.
I'm afraid we have to work with shared memory ;-(
Please help us,
with regards,
Tijmen