Is there any reason I shouldn't do database calls from the destructor?
Posted
by ryeguy
on Stack Overflow
See other posts from Stack Overflow
or by ryeguy
Published on 2010-05-04T14:01:51Z
Indexed on
2010/05/04
14:08 UTC
Read the original article
Hit count: 126
I want to create a sort of datamapper library, where you'd do something like this:
$users = Users::getTable();
$users->add($newUser1);
$users->add($newUser2);
Now $users
contains 2 user records, but they aren't yet persisted to the database. To be efficient, I'd like to flush them all at once. I would like to have a flush()
method to do this (not an issue), but I'd also like for it to happen implicitly when the $users
table reference falls out of scope. Is there any reason I shouldn't do this in the destructor?
© Stack Overflow or respective owner