result = doFirstThing(); if (result==failed) { rollback transaction; return (failed, "Failed because FirstThing failed because of whatever); } result = doThing2(); if (result==failed) { rollback transaction; return (failed, "failed because thing2 failed"); } result = doThing3(); if (result==failed) { rollback transaction; return (failed, "failed because thing3 failed"); } ////////////// // cleaner way, using exceptions try { doFirstThing(); doThing2(); doThing3(); } catch (Exception $ex) { rollback transaction; return('failed', "Failed because ".$ex->getMessage()); }