开发者

Alternatives to persisting objects than using __destruct() in PHP

开发者 https://www.devze.com 2022-12-29 01:25 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消