Skip to content

Instantly share code, notes, and snippets.

@j4mie
Created September 21, 2010 02:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j4mie/589081 to your computer and use it in GitHub Desktop.
Save j4mie/589081 to your computer and use it in GitHub Desktop.
PHP __get weirdness
<?php
// You can do some very odd things with PHP's __get method
class Chain {
private $chain = array();
public static function it() {
return new self;
}
public function __get($property) {
$this->chain[] = $property;
return $this;
}
public function __toString() {
return join(" ", $this->chain);
}
}
echo Chain::it()->Building->up->a->chain->oh->yeah;
// prints "Building up a chain oh yeah"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment