Skip to content

Instantly share code, notes, and snippets.

@rightgo09
Created December 1, 2015 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rightgo09/20ea0d301c3bc23919fe to your computer and use it in GitHub Desktop.
Save rightgo09/20ea0d301c3bc23919fe to your computer and use it in GitHub Desktop.
<?php
class Any implements IteratorAggregate
{
private $v;
public function __construct($v)
{
$this->v = $v;
}
public function __get($name)
{
if (array_key_exists($name, $this->v)) {
if (is_array($this->v[$name])) {
return new self($this->v[$name]);
}
else {
return $this->v[$name];
}
}
return null;
}
public function getIterator()
{
foreach ($this->v as $k => $v) {
yield $k => new self($v);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment