Alternatives to persisting objects than using __destruct() in PHP
I usually use a classes destructor met开发者_StackOverflow中文版hod __destruct() to persist objects to session or what have you. It is just very convinient, but I'm curious to if there are any other methods that are equally appealing. Do you know of such?
The curiousity arose as I was to merge/utilize two frameworks that both made use of __destruct() for persistance resulting in a race-problem.
You should handle the persistence manually and explicitly. Not only is it more intuitive for anyone who has to read your code, but it's not a good idea to depend on PHP's garbage collector to do important jobs for you, since it can be unpredictable. Your objects may not be saved in the right order, either, if that matters.
It also prevents many debugging nightmares.
精彩评论