php代码:——————————————————————————–
function factorymethod($class_type)
{
switch ($class_type)
{
case “foo”:
$obj = new myfoo();
break;
case “bar”:
$obj = new mybar();
break;
}
return $obj;
}
$object = factorymethod(“foo”);
$object->method()->method()
$copy_of_object = $object->__clone();
class myclass
{
function __destruct()
{
… // run destructor code
}
}
delete $object;
class shape {
function __construct()
{
// shape initialization code
…
}
…
};
class square extends shape
{
function __construct()
{
parent::__construct();
// square-specific initialization code
…
}
…
};
class foo
{
private $priv_var;
function some_method(…)
{
$this->priv_var = …; // zend 上写的是:$priv_var = …; ,我没试过。
}
};
class logger
{
static $m_instance = null;
function instance()
{
if(logger::$m_instance == null)
{
logger::$m_instance = new logger();
}
return logger::$m_instance;
}
function log()
{
…
}
};
$logger = logger::instance();
$logger->log(…);
try
{
…code
if (failure)
{
throw new myexception(“failure”);
}
…code
}
catch ($exception)
{
… handle exception
throw $exception; // re-throw exception.
}
