According to you, what is the best solution in PHP to ensure the course of several php functions ?
For example function A must return True to initiate the B function, and the B function must return True to initiate another function…
Is there a system like Rollback / Commit in SQL to ensure that in PHP please ?
Thank you.
Doing a chain of functions would look something like this:
But if I understand correctly you want to perform a serie of operations and only if they are all successful you want them to be final, otherwise you want to undo all the operations?
In this case it is hard to tell how you should implement this, cause you don’t tell what you want to achieve.
But I can give you some advise. Most operations that are not reversable do have many possible checks. For example, if you want to be sure a file will be deleted from the filesystem you can first check if the file is writable (
is_writable) and even exists (file_exists). If you first do all the checks of all operations and afterwards execute the operations, you can be pretty sure they will be executed successfully. Ofcourse it’s possible you forget checks, or some things can’t be checked, but I don’t see an other option to fix this.