Standardized returning values - is it a good or bad idea
<p>I'm working in PHP (but in this case I think the programming language doesn't matter), and in my class methods I usually meet the following situations:</p>

<ol>
<li>Method has to return <em>true</em> or <em>false</em></li>
<li>Method has to return <em>true</em> or <em>error message</em></li>
<li>Method has to return <em>true</em> + <em>success message</em> or <em>false</em> + <em>error message</em></li>
<li>Method has to return <em>true</em> + <em>success results (object, array, whatever)</em> or <em>false</em></li>
<li>Method has to return <em>true</em> + <em>success results (object, array, whatever)</em> or <em>false</em> + <em>error message</em> </li>
<li>etc.</li>
</ol>

<p>My problem is, that when I use this class methods in my code somewhere I always have to come back to the class, and check what is the method actually returning: simply <em>true</em> or <em>false</em>, <em>true</em> or <em>error message</em>, etc.</p>

<p>Is a good idea to standardize the returning values? If yes, how?</p>

<p>My idea is:</p>

<ol>
<li>if function has to return <em>true</em> or <em>false</em> then simply return <em>true</em> or <em>false</em></li>
<li><p>if function has to return <em>true</em> or <em>error message</em> then:</p>

<p><code>if (success)
{
    return array(
         TRUE,
         null
    );
}
else
{
    return array(
        FALSE,
        $error_message
    );<br>
}</code></p></li>
<li><p>if function has to return <em>true</em> + <em>success message</em> or <em>error message</em> then:</p>

<p><code>if (success)
{
    return array(
         TRUE,
         $success_message,
    );
}
else
{
    return array(
        FALSE,
        $error_message
    );<br>
}</code></p></li>
<li><p>etc.</p></li>
</ol>

<p>I hope you understand guys my <em>problem</em>, even thought my explanation wasn't so good :)
What are your suggestions, or best practices? How should I handle this?</p>

<p>UPDATE:
Let's take a simple example:</p>

<pre><code>function login($username, $password) 
{
    // Login logic here ..
    if ($logged_in) 
    {
        return TRUE;
    }
    {
        return $error_message;
    }
}
</code></pre>

<p>So the correct way to do this will be: return <em>true</em>, or <em>throw exception</em>, and when calling the login method do in withing a <em>try catch</em>. So, when somethong goes wrong (validation fails, etc) I sould use exceptions.</p>
