Php object-oriented clever application

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.