Development Blog With Code Updates : Developercast.com

August 8, 2008

Cormac’s Blog: Lazy loading of object variables in php using __get()

Filed under: Development — @ 3:22 pm

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.

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress