Php object-oriented clever application
Class test {public $ a, $ B; public function _ construct ($ a, $ B) {$ this-> a = $; $ this-> B = $ B;} public function set ($ var, $ val) {$ this-> $ var. = $ val; return $ this;} public function get () {echo $ this->. '-'. $ this-> B ;}} class test2 {public $ obj; public function _ construct ($ obj) {$ this-> obj = $ obj;} public function get () {$ this-> obj-> get () ;}$ a = 'aaaaa'; $ B = 'bbbbbb'; $ set = 'set '; /// 1. chained call method $ test = new test ($ a, $ B); $ test2 = new test2 ($ test ); $ test-> $ set ('A', '000000')-> $ set ('B', '000000'); // call it using string variables (class) method ps: another clever php application // 2. Multiple call methods $ test-> $ set ('A', '123 '); $ test-> $ set ('B', '20140901'); unset ($ test); $ test2-> get ();
Although test2 instantiation has passed in test, test can still set parameters through the set method, and then affect test2.
Result of the above execution program: (both of the above can produce the same result)
Aaaaa111111-bbbbbb222222