In my PHP projects, I tried several different clock cycles. I came up with the following solution, which seems to work well for me:
First, any major PHP application that I write has some sort of central singleton that controls data and behavior at the application level. Object "Application". I mention here because I use this object to collect the generated feedback from every other module. The rendering module may request the application object for feedback, which it considers should be displayed to the user.
, . , "AddError (, , )" "GetErrors()" "ClearErrors". "AddError" : () ( "global" ), .
, , :
, 'Object' : AddError ClearErrors GetErrorCodes GetErrorsAsStrings GetErrorCount , , HasError
class MyObject extends Object
{
public function DoThing()
{
$this->ClearErrors();
if ([something succeeded])
{
return true;
}
else
{
$this->AddError(ERR_OP_FAILED,"Thing could not be done");
return false;
}
}
}
$ob = new MyObject();
if ($ob->DoThing())
{
echo 'Success.';
}
else
{
$ob->TrySomethingElse();
}
echo implode('<br/>',$GLOBALS['app']->GetErrorsAsStrings());
, , :
- , , ,
- , , , .
- , , . "" , . .
- ( ) , , .