I've developed and become comfortable with a OO PHP system I've developed. I've set it up so that I can reuse it on projects. The one thing I feel it is lacking is good error handling. My question is, how do you handle errors in a OO PHP application? How do you pass errors from the business layer to the presentation layer? Specific code examples would be great.
Below is a very rough example of how I handle errors
SomeClass.php
Index.phpCode PHP:class SomeClass { public function someFunc(){ $errors = Array(); //do some processing if(somethingFails){ $errors[] = "Something Failed"; } return $errors; } }
Code PHP:require_once("SomeClass.php"); $class = new SomeClass(); $errors = $class->someFunc(); if(count($errors>0)){ $tmpl = new Template(); //templating class $tmpl->errors = $errors; }else{ //Process application }
Template.php
Code PHP:$errors = $tmpl->errors; if(count($errors) > 0){ foreach($errors as $err){ //Print Error } }



Reply With Quote




Bookmarks