想学php5的来看看!!_PHP教程
程序员文章站
2022-04-01 20:04:44
...
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.
}
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.
}
推荐阅读
-
想学PHP来兄弟连是正确的选择 初识兄弟连三周
-
PHP5中的this,self和parent关键字详解教程
-
在PHP中使用魔术方法__CLASS__来获取类名的教程
-
解析如何通过PHP函数获取当前运行的环境 来进行判断执行逻辑(小技巧)_PHP教程
-
解析php中用PHPMailer来发送邮件的示例(126.com的例子)_PHP教程
-
Win2003下APACHE + PHP5 + MYSQL4 + PHPMYADMIN的简易安装配置_PHP教程
-
用实例来理解PHP5异常处理_PHP教程
-
Windows下PHP5和Apache的安装_PHP教程
-
php number_format() 函数通过千位分组来格式化数字的实现代码_PHP教程
-
如何使用动态共享对象的模式来_PHP教程