想学php5的来看看!!-PHP技术-3P代码网
繁体中文
设为首页
加入收藏
当前位置:PHP技术首页 >> PHP基础 >> 想学php5的来看看!!

想学php5的来看看!!

2005-01-15 08:00:00  作者:  来源:互联网  浏览次数:0  文字大小:【】【】【
简介:PHP代码:-------------------------------------------------------------------------------- function FactoryMethod($class_type) { switch ($class_type) { case “foo”: $obj = new MyFoo(); break; case ...
关键字:php5

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.

}

责任编辑:admin
相关文章