Created
November 15, 2014 15:11
-
-
Save AlexTiTanium/db61a04b6276909f8045 to your computer and use it in GitHub Desktop.
php simple stub object
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 stub implements ArrayAccess, Countable, Iterator { | |
public $position = 0; | |
public function __get($name){ | |
return new stub(); | |
} | |
public function __call($name, $lo){ | |
return new stub(); | |
} | |
public function offsetExists($offset) | |
{ | |
return true; | |
} | |
public function offsetGet($offset) | |
{ | |
return new $this(); | |
} | |
public function offsetSet($offset, $value) | |
{ | |
} | |
public function offsetUnset($offset) | |
{ | |
} | |
public function count() | |
{ | |
return 2; | |
} | |
public function __toString(){ | |
return 'text'; | |
} | |
function rewind() { | |
$this->position = 0; | |
} | |
function current() { | |
return new $this(); | |
} | |
function key() { | |
return $this->position; | |
} | |
function next() { | |
++$this->position; | |
} | |
function valid() { | |
if($this->position >2) return false; | |
return true; | |
} | |
} | |
$stub = new stub(); | |
echo $stub['fsdfsdf']['fdsfdf']['fsdfsdfsd']; | |
echo $stub; | |
echo $stub->fdsfsdf; | |
echo $stub->ffsdfdf(); | |
echo count($stub); | |
foreach($stub as $item){ | |
echo '---------------'.$item['fdfsdf']['ggergerg']; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment