Skip to content

Instantly share code, notes, and snippets.

@MindTwister
Created December 22, 2010 11:08
Show Gist options
  • Save MindTwister/751392 to your computer and use it in GitHub Desktop.
Save MindTwister/751392 to your computer and use it in GitHub Desktop.
Abusing magic methods because you can
<?php
error_reporting(E_ALL);
class O_o
{
public $wth,$mode,$num;
function __construct()
{
$this->wth = "";
$this->mode;
}
function __get($yayme)
{
if($this->mode == "")
{
$this->wth .= $yayme." ";
}
elseif($this->mode == "select")
{
if($yayme == "from")
{
$this->wth = substr($this->wth,0,strlen($this->wth)-2) . " ";
$this->wth .= $yayme . " ";
}
else
{
$this->wth .= $yayme . ", ";
}
}
elseif($this->mode == "where")
{
if(in_array($yayme,array("and",'or')))
{
$this->wth .= " ".$yayme." ";
}
else if($this->num %2 == 0)
{
$this->wth .= $yayme." = ";
$this->num++;
}
else
{
$this->wth .= "`".$yayme."`";
$this->num++;
}
}
switch($yayme)
{
case 'select':
$this->mode = $yayme;
break;
case 'where':
$this->mode = $yayme;
break;
case 'from':
$this->mode = "";
break;
default:
break;
}
return $this;
}
function execute()
{
echo $this->wth;
}
}
$a = new O_o();
$a->select->id->email->from->web8_shop_customer->where->name->hello->and->lang->dk->execute();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment