terminal-auspicious

Topics

programming

php drupal scheme scheming macros design patterns da la

design

design css

random thoughts

scribbles

alter ego

other me 'em that link us my space me linked in

Collections

Programmable web
PHP design patterns

PHP Design Patterns

  • A catalogue of php design pattern shorts
    • Accumulator passing
    • Closure
    • Control abstraction
    • Coroutines (generator based)
    • Dynamic dispatch
    • Dynamic loading
    • Facade
    • Factory and Abstract Factory
    • Fluent Interfaces/ Method chaining
    • Generator (iterator protocol based)
    • Generic function
    • Hooks
    • Interpreter
    • Iterator (based on protocol method)
    • Lazy evaluation
    • Memoization
    • Nested scope
    • Observer
    • Partial Evaluation
    • Protocol method
    • Proxy
    • Singleton
    • State
    • Strategy Pattern
  • Models, records, databases, friends and foes

Similar things

  • Learning lessons from Lisp or patterns and languages in PHP
  • Emulating closures in PHP
  • Some ways to use saved state with closures in php
  • Scoped php functions or more ways to abuse php
  • PHP Design Patterns
  • Strategy Pattern
  • Memoization
  • Singleton
  • Factory and Abstract Factory
  • Facade

guild
Home » PHP Design Patterns » A catalogue of php design pattern shorts

Lazy evaluation

design patterns | php
Intent
A function/method call results in a promise for future computation
Motivation
We want to be able to postpone the effects of a computation, for example delay printing from a function to webserver output until whole web-page is assembled
Implementation
Instead of evaluating a function, we deliver a promise - a callable with no arguments, which when forced is executed
Examples
//for simplicity handle only functions with one argument class promise { private $args = null; private $func = null; function __construct($func, $args) { $this->func = $func; $this->args = $args; } function evaluate() { call_user_func($this->func,$this->args); } } function delay( $func, $arg ) { return array(new promise($func, $arg), 'evaluate'); } //example use ... $chunks[] = delay('a_printer',$a_variable); ... foreach($chunks as $chunk ) { if(is_callable($chunk)) { $chunk(); //force - this does it's own printing in this example } else { print $chunk; } }
‹ Iterator (based on protocol method)upMemoization ›
printer-friendly version | add new comment
Home » PHP Design Patterns » A catalogue of php design pattern shorts

dikini.net

spreading confusion by accident since 1970