title: Returning useful error messages with PHP
body: <p>I don't understand how to properly create and return useful error messages with PHP to the web.</p>
  
  <p>I have a class</p>
  
  <pre><code>class Foo {
      const OK_IT_WORKED = 0;
      const ERR_IT_FAILED = 1;
      const ERR_IT_TIMED_OUT = 3;
  
      public function fooItUp(){
          if(itFooed)
            return OK_IT_WORKED;
          elseif(itFooedUp)
            return ERR_IT_FAILED;
          elseif(itFooedOut)
            return ERR_IT_TIMED_OUT;
      }
  }
  </code></pre>
  
  <p>And another class that uses this class to do something useful, then return the result to the user. I am just wondering where I put the string value for all my error messages.</p>
  
  <pre><code>class Bar {
      public function doFooeyThings(stuff){
          $res = $myFoo-&gt;fooItUp();
          // now i need to tell the user what happened, but they don't understand error codes
          if($res === Foo::OK_IT_WORKED)
             return 'string result here? seems wrong';
          elseif ($res === Foo::ERR_IT_FAILED)
             return Foo::ERR_IT_FAILED_STRING; // seems redundant?
          elseif($res === Foo:ERR_IT_TIMED_OUT)
             return $res; // return number and have an "enum" in the client (js) ?
      }
  
  }
  </code></pre>