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. }
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号