Created
December 1, 2015 15:33
-
-
Save rightgo09/20ea0d301c3bc23919fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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