Jump to content

Php Error Messaging


designanddev

Recommended Posts

Have a look at this little sample I made up for you. It covers one way (my preffered way) of getting info out of the class:

<?php
class sample {
   public $errors;

   public function __construct(){
       $this->loadSampleErrors();
   }

   private function loadSampleErrors(){
       $this->errors[] = array('errorInfo'=>'Form Fill Error', 'userMsg'=>"You forgot to enter your username!");
       $this->errors[] = array('errorInfo'=>"Connection to server failed", 'userMsg'=>"A connection to the database server could not be established!");
       $this->errors[] = array('errorInfo'=>"Database Not Found", 'userMsg'=>"Unable to locate the selected database!");
   }

   public function pushErrorData(){
       return $this->errors;
   }
}
$sample = new sample();
//do some stuff
//....
//now check for errors:
if(!empty($sample->errors)){
//got errors? best show them to the user then...
echo "The Following Errors Were Encounterd :-<br /><br />";
$errorList = $sample->pushErrorData();
foreach($errorList as $error){
echo "an internal error of type <span style=\"font-weight:bold;\"> \"{$error['errorInfo']}\"</span> has been generated with the message :- {$error['userMsg']}";
echo"<br />----------------------------------------------<br />";
}
}
?>

 

you can run this script as is and see the output yourself.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.