Skip to content

Instantly share code, notes, and snippets.

@AlexTiTanium
Created November 15, 2014 15:11
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 AlexTiTanium/db61a04b6276909f8045 to your computer and use it in GitHub Desktop.
Save AlexTiTanium/db61a04b6276909f8045 to your computer and use it in GitHub Desktop.
php simple stub object
<?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