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

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

Nested scope

design patterns | php
Intent
Create a composable runtime hierarchy of data and behaviour
Motivation
We want dynamic means of modifying complex runtime structures
Implementation
Use php magic to dynamically dispatch requests to parent methods
Examples
class scope { var $parent; function __call( $name ) { if(isset($parent[$name]) { return $parent[$name](); } throw( new someException() ); } function let( $name, $value ) { if(is_object($value)) { //hygiene if(isset($this->$name)) { $this->$name->parent = null; } $this->$name = $value; $this->$name->parent = $this; } } //alternative let function let($parent, $name, $class) { $parent->$name = new $class(); $parent->$name->parent = array($parent,$name); } ?>
Notes
  • A concept related to and very often mistaken (mixed) (by me) with (for) closures
  • the let method can be folded into __set if we want this behaviour to the default for assignments to object fields
‹ MemoizationupObserver ›
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