Home arrow PHP arrow Deferring Class Property Creation with Lazy Loading

Deferring Class Property Creation with Lazy Loading

Welcome to the conclusion of a five part series that shows you how to implement lazy and eager loading in PHP 5. These two design patterns allow you to handle the resources for an application in very different ways. Through numerous code examples, I've demonstrated when it is appropriate to use each method.

  1. Deferring Class Property Creation with Lazy Loading
  2. Review: eagerly loading properties of a class
  3. Applying lazy loading to class properties
  4. Building a final script
By: Alejandro Gervasio
Rating: starstarstarstarstar / 2
September 24, 2009

print this article



As you may know as a PHP programmer, one of the most important facets that must be tackled during the development of a web application is properly establishing the way that its resources will be managed. While there are many factors involved in this process that will affect, both directly and indirectly, the end performance of a certain program, it's possible to use well-trusted approaches to define how "early" a specific resource will be loaded by the program in question.

In software programming, there are two design patterns that permit you to achieve this definition procedure with relative ease, popularly known as lazy and eager loading. As you may have guessed, in the first case loading a determined resource will be delayed or deferred until an application (or a part of it) actually requests it, while in the last case the resource will be loaded as soon as possible, regardless of whether or not it's required by the application.

In this particular context, the term "resource" references anything suitable to use within a PHP-driven program, ranging from classes to objects, configuration files, database result sets and so forth. How much success you can achieve when applying the aforementioned patterns will depend strongly on the type of resource you're handling.

However, if you've been a loyal follower of this article series and have already read all of the tutorials that precede this one, then it's probable that at this point you're familiar with using eager and easy loading in PHP 5. In those articles I explained how to apply these patterns when including a class within a script, as well as when declaring and assigning values to its properties.

This last scenario was recreated in the last article, where I showed how a class that stored user-related data eagerly assigned default values to its declared properties, showing that eager loading can be used in many different cases.

Nevertheless, if it was possible to eagerly handle properties of a class, then in theory it would also be feasible to invert the process and manipulate those properties in a lazy fashion, right? Well, that's true, and in this final chapter of this series I'm going to show you through some code samples how to accomplish this with minor hassles.

Now start reading this last part of the series!

>>> More PHP Articles          >>> More By Alejandro Gervasio

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: