class IMessge - returns user message types | loop similar items This class holds message types that are sent to the client which knows what to do with them.  It is basically a small registry pattern where I can consolidate message types. |P| and |F| are read by the client...and I use these for simple data passing when I don't need the complexity of JSON.  The programmer is expected to know which messages types are available.

I've added in a array_key_exists() as a defensive measure against a progammer calling a message that does not exit.  I did this as someone said this is best practice...I'm looking for a second opinion...as in this case it is not a big deal but overall "defensive coding" would increase my library size / efficiency by 10-20%.  Can I take this out?

&lt;?php
class IMessage
{
    private $PASS = '|P|';
    private $FAIL = '|F|';
    private $messages = array();
    public function __construct()
    {
        $this-&gt;messages['PASS'] =  $this-&gt;PASS;
        $this-&gt;messages['name'] =  $this-&gt;FAIL . 'name';
        $this-&gt;messages['email'] = $this-&gt;FAIL . 'email_s';
        $this-&gt;messages['pass'] =  $this-&gt;FAIL . 'pass';
        $this-&gt;messages['url'] =   $this-&gt;FAIL . 'url';
        $this-&gt;messages['title'] = $this-&gt;FAIL . 'title';
        $this-&gt;messages['tweet'] = $this-&gt;FAIL . 'tweet';
        $this-&gt;messages['empty'] = $this-&gt;FAIL . 'empty';
        $this-&gt;messages['same'] =  $this-&gt;FAIL . 'same';
        $this-&gt;messages['taken'] = $this-&gt;FAIL . 'taken';
        $this-&gt;messages['validate'] = $this-&gt;FAIL . 'validate';
    }
    public function get( $type )
    {
        if( !array_key_exists($type, $this-&gt;messages ) ) 
        {
            echo "Programmer Error: You called a key that does not exist";
        }
        else
        {
            return $this-&gt;messages[ $type ];
        }
    }
}
Well, you are doing this a little redundantly...

$keys = array(
    'name',
    'email',
    //etc...
);

$messages = array(
    'PASS' =&gt; $this-&gt;PASS,
);

foreach( $keys AS $key ) { $messages[ $key ] = $this-&gt;FAIL . $key; }

$this-&gt;messages = $messages;


Also, your get function has a fatal error. You currently have a check to see if a key exists, and if it doesn't it will output an error message. This is incomplete, if that key doesn't exist it will output the error message then PHP will throw an undefined index error because $key does not exist. To avoid this you should have it return that error message when you set it or have it return FALSE. I think such a check is good, since it seems you are dealing with user supplied information. If this was a private method and you knew the information you were passing it was reliable, then I would say its unnecessary.