PHP Code:--------------------------------------------------------------------------------function FactoryMethod ($ Class_type) {switch ($class _type) {case ' foo ': $obj = new Myfoo (); break, case ' bar ': $obj = new Mybar (); break;} retur n $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 = ...; I haven't tried. } }; Class Logger {static $m _instance = null, function Instance () {if (Logger:: $m _instance = null) {Logger:: $m _instance = NE W 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 $EXCEP tion; Re-throw exception. }
http://www.bkjia.com/PHPjc/532143.html www.bkjia.com true http://www.bkjia.com/PHPjc/532143.html techarticle PHP Code:--------------------------------------------------------------------------------function FactoryMethod ($class _type) {switch ($class _type) {case "foo": $obj = new M ...