Re: Re: Question about __destruct()
| From: | Stut | Date: | Wed, 22 Oct 2008 08:26:34 +0000 |
| Subject: | Re: Re: Question about __destruct() | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-282231@lists.php.net to get a copy of this message | ||
On 22 Oct 2008, at 00:22, Jochem Maas wrote:
Stut schreef:Nothing complicated. The core objects in my application are all cached in memcache. If anything changes in an object it changes an internal flag to indicate that it's dirty. The destructor checks that flag and if the object is dirty it updates the cached version (the DB version having been updated as changes were made).I use destructors to update dirty objects in memcache.care to eloborate ... sounds interesting.
I also use themIt's one of the things that help to keep my controllers clean. The pattern goes something like this... $page = Layout::Create('style'); $page->title = 'This is the page title'; $page->keywords = 'shiny,happy,page'; $page->description = 'It\'s a shiny happy page.'; $page->Start(); $data = array(); // Business logic here populating $data with vars for the page template $page->Render('dir/to/template.tpl.php', $data); I've found that pattern works very well for me and not having to worry about calling a method to output the footer it just one feature of a very useful templating system.in my template class to optionally automagically output the footer without needing an explicit call on each page.not sure if I find that of much use, I see the validity but 1 LOC to eplicitly output a page footer seems to me to be less of a wtf than an(other) bit of auto-magic to save what is probably a very short simple method call.
Agreed, you do need to be careful depending on what you want to achieve. You've gotta remember that PHP is not (yet) an OOP language at heart.They're far from useless.true. but they are limited, there is no garantee any other object will still exist when a particular dtor is run [at shutdown] which means a heavy OO codebase cannot have object automated object interaction at shutdown ... there are other gotchas (e.g. closed file descriptors to STDIN/STDOUT)
interaction with memcache though is a really good example. and I'd like to learn a little more :-DAnd I hope you did ;) -Stut -- http://stut.net/