Manage error text

Hi,

I’ve created a function to manage errors in php, this is the function:

function km_notice($km_notice_title, $km_notice_message, $km_notice_code, $km_notice_status){

    $km_notice = array(
        'notice_title' => htmlspecialchars($km_notice_title),
        'notice_message' => htmlspecialchars($km_notice_message),
        'notice_code' => htmlspecialchars($km_notice_code),
        'notice_status' => htmlspecialchars($km_notice_status)
    );

    return json_encode($km_notice);
}

And then i use it in the following way:

echo km_notice('title', 'message', 'code', 'error');

Now my problem is how can I store messages in a single file so if in the future if I want to change the text I don’t have to edit the specific file containing the message? I suppose I could use constants but I’m wondering if there is another method I’m not aware of. Something a .po file maybe?

many thanks

I think arrays would work. Instead of hard coded arguments scatted about the function calls could be like

echo km_notice($invalid_password['title'],$invalid_password['message'],$invalid_password['code'],$invalid_password['status']); 

Or you could change the function to take an array instead.

Just curious, have you considered Monolog?

It’s pretty much the defacto strandard for logging in PHP. There really is no need to reinvent the wheel here :slight_smile:

There’s a whole lot of logging tools for choice, e.g.:

Splunk – Loggly – Graylog – Papertrail – TestView – Logstash – SumoLogic

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.