Skip to content

Instantly share code, notes, and snippets.

@andrienko
Created December 7, 2013 12:19
Show Gist options
  • Save andrienko/7840464 to your computer and use it in GitHub Desktop.
Save andrienko/7840464 to your computer and use it in GitHub Desktop.
I did it because I can.
<?
class a{
public $something;
function output(){
echo("A happens!<br>");
}
}
class b{
public $something;
function output(){
echo "Let's do something B<br>";
}
}
class test{
public $object;
function __construct($in="a",$args=null){
if($in=="a")$this->object=new a($args);
else $this->object=new b($args);
}
function __call($name,$args){
return $this->object->$name($args);
}
function __get($name){
return $this->object->$name;
}
function __set($name,$value){
return $this->object->$name=$value;
}
function __isset($name){
return isset($this->object->$name);
}
function __unset($name){
unset($this->object->$name);
}
}
$myTest=new test("b");
$myTest->output();
$myTest->something="Variable";
echo($myTest->something);
?>
@andrienko
Copy link
Author

new test("a");

Will produce an object of "a"

new test("b");

Will produce an object of "b"

There even IS a practical approach for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment