public
Created

PHP __get weirdness

  • Download Gist
chains.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
<?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"

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.