Best way to handle error descriptions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Best way to handle error descriptions

Post by yacahuma »

If your API constains error description messages, what is the best design(A or B??)

$code = array(
'100'=>'message in english here',
'110'=>'message in english here');


//OPTION A
include 'error_in_{$lan}.php'; //$lan is 'es','en', etc..
$error = class->function(xxx);
echo $codes[$error];


//OPTION B
$error = class->function(xxx);
$error->getDescription($lan);
cptnwinky
Forum Commoner
Posts: 84
Joined: Sat Dec 27, 2008 10:58 am
Location: Williamstown, MA

Re: Best way to handle error descriptions

Post by cptnwinky »

If I understand correctly I think it would depend on how big that array of error codes gets. If it's a large array you certainly don't want to be declaring it upon every page load, that would just waste memory and processing power. Thus, including an error file would probably be the best thing. It also allows for easier abstraction.
Post Reply