News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Cormac's Blog:
Lazy loading of object variables in php using __get()
August 08, 2008 @ 14:22:51

Recently, Cormac posted this look at a method for lazy loading on variables in an object with the magic __get method.

I used the magic method __get() to load the images into the [Product] object when they were needed. __get() is called whenever something tries to access a variable that is not set or publically accessible, so basically I used that to load the images whenever some other piece of code tried to access Product::images.

He includes a quick bit of code that fires off an internal private method for the class that loads up the images. In his example, if they're already loaded, it never gets called.

0 comments voice your opinion now!
lazy loading get method image product


blog comments powered by Disqus

Similar Posts

Brandon Savage: Private Methods Considered Harmful ("Do This, Not That" Excerpt)

PHP-Coding-Practices.com: Composing Methods: Split Temporary Variable

PHPMaster.com: From Zero to Cloud: Setting up an EC2 Sandbox, Part 3

Arnold Daniels' Blog: PHP != Ruby (and why PHP needs more advanced OO stuff)

PHP-Coding-Practices.com: Making CakePHP's Pagination work with Model::expects()


Community Events





Don't see your event here?
Let us know!


conference community release version voicesoftheelephpant symfony podcast framework list opinion laravel language composer interview artisanfiles security tool library series introduction

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework