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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.