Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@andrienko andrienko commented Dec 7, 2013

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