This article details the php prototype implementation code examples. if you need code, refer
Php prototype implementation code example
Type = $ type; $ this-> obj = new Obj ();} public function getType () {echoLine ($ this-> type);} public function getObj () {return $ this-> obj ;}}$ p = new Prototype ('prototype'); $ c = clone $ p; // shortest clone var_dump ($ c ===$ p); // falsevar_dump ($ p-> getObj () ====$ c-> getObj ()); // true // ============================================ ====================/// deep clone function deepClone ($ obj) {if (! Is_object ($ obj) return null; return unserialize (serialize ($ obj);} $ dp = deepClone ($ p); var_dump ($ dp = $ p ); // falsevar_dump ($ p-> getObj () ===$ dp-> getObj (); // false
The above is the details of the code instance implemented in the php prototype mode. For more information, see other related articles in the first PHP community!